Skip to content

Commit 6833f5e

Browse files
authored
Merge pull request #348 from FrameworkComputer/fp_led_control
[add] add host cmd to control FP led brightness
2 parents cdbb6fa + d699943 commit 6833f5e

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

board/hx20/host_command_customization.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ static enum ec_status factory_mode(struct host_cmd_handler_args *args)
136136
system_set_bbram(STSTEM_BBRAM_IDX_CHASSIS_VTR_OPEN, 0);
137137
system_set_bbram(STSTEM_BBRAM_IDX_CHASSIS_WAS_OPEN, 0);
138138
system_set_bbram(SYSTEM_BBRAM_IDX_AC_BOOT, 0);
139+
system_set_bbram(STSTEM_BBRAM_IDX_FP_LED_LEVEL, 0);
139140
}
140141

141142
return EC_SUCCESS;

board/hx20/host_command_customization.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ struct ec_response_bb_retimer_control_mode {
174174
uint8_t status;
175175
} __ec_align1;
176176

177+
#define EC_CMD_FP_LED_LEVEL_CONTROL 0x3E0E
178+
179+
struct ec_params_fp_led_control {
180+
uint8_t set_led_level;
181+
uint8_t get_led_level;
182+
} __ec_align1;
183+
184+
enum fp_led_brightness_level {
185+
FP_LED_BRIGHTNESS_HIGH = 0,
186+
FP_LED_BRIGHTNESS_MEDIUM = 1,
187+
FP_LED_BRIGHTNESS_LOW = 2,
188+
};
189+
190+
struct ec_response_fp_led_level {
191+
uint8_t level;
192+
} __ec_align1;
193+
177194
#define EC_CMD_CHASSIS_OPEN_CHECK 0x3E0F
178195

179196
struct ec_response_chassis_open_check {

board/hx20/led.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "power_button.h"
1717
#include "hooks.h"
1818
#include "host_command.h"
19+
#include "host_command_customization.h"
20+
#include "system.h"
1921
#include "util.h"
2022
#include "diagnostics.h"
2123

@@ -29,6 +31,9 @@
2931
#define BREATH_ON_LENGTH 62
3032
#define BREATH_OFF_LENGTH 200
3133

34+
#define FP_LED_HIGH 55
35+
#define FP_LED_MEDIUM 40
36+
#define FP_LED_LOW 15
3237

3338
const enum ec_led_id supported_led_ids[] = {
3439
EC_LED_ID_LEFT_LED,
@@ -38,6 +43,7 @@ const enum ec_led_id supported_led_ids[] = {
3843
const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
3944

4045
int power_button_enable = 0;
46+
static uint8_t led_level;
4147

4248
struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = {
4349
/* Red, Green, Blue */
@@ -55,7 +61,7 @@ struct pwm_led pwr_led_color_map[EC_LED_COLOR_COUNT] = {
5561
[EC_LED_COLOR_GREEN] = { 0, 15, 0 },
5662
[EC_LED_COLOR_BLUE] = { 0, 0, 0 },
5763
[EC_LED_COLOR_YELLOW] = { 0, 5, 10 },
58-
[EC_LED_COLOR_WHITE] = { 55, 0, 0 },
64+
[EC_LED_COLOR_WHITE] = { FP_LED_HIGH, 0, 0 },
5965
[EC_LED_COLOR_AMBER] = { 0, 5, 30 },
6066
};
6167

@@ -320,6 +326,12 @@ static void led_configure(void)
320326
for (i = 0; i < PWM_CH_COUNT; i++) {
321327
pwm_enable(i, 1);
322328
}
329+
330+
system_get_bbram(STSTEM_BBRAM_IDX_FP_LED_LEVEL, &led_level);
331+
332+
if (led_level)
333+
pwr_led_color_map[EC_LED_COLOR_WHITE].ch0 = led_level;
334+
323335
led_tick();
324336
}
325337

@@ -332,3 +344,35 @@ void power_button_enable_led(int enable)
332344
power_button_enable = enable;
333345
}
334346

347+
static enum ec_status fp_led_level_control(struct host_cmd_handler_args *args)
348+
{
349+
const struct ec_params_fp_led_control *p = args->params;
350+
struct ec_response_fp_led_level *r = args->response;
351+
352+
if (p->get_led_level) {
353+
system_get_bbram(STSTEM_BBRAM_IDX_FP_LED_LEVEL, &r->level);
354+
args->response_size = sizeof(*r);
355+
return EC_RES_SUCCESS;
356+
}
357+
358+
switch (p->set_led_level) {
359+
case FP_LED_BRIGHTNESS_HIGH:
360+
led_level = FP_LED_HIGH;
361+
break;
362+
case FP_LED_BRIGHTNESS_MEDIUM:
363+
led_level = FP_LED_MEDIUM;
364+
break;
365+
case FP_LED_BRIGHTNESS_LOW:
366+
led_level = FP_LED_LOW;
367+
break;
368+
default:
369+
return EC_RES_INVALID_PARAM;
370+
break;
371+
}
372+
373+
system_set_bbram(STSTEM_BBRAM_IDX_FP_LED_LEVEL, led_level);
374+
pwr_led_color_map[EC_LED_COLOR_WHITE].ch0 = led_level;
375+
376+
return EC_RES_SUCCESS;
377+
}
378+
DECLARE_HOST_COMMAND(EC_CMD_FP_LED_LEVEL_CONTROL, fp_led_level_control, EC_VER_MASK(0));

chip/mchp/system.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum hibdata_index {
5252
HIBDATA_INDEX_CHASSIS_VTR_OPEN = 34,
5353
HIBDATA_INDEX_VPRO_STATUS = 35,
5454
HIBDATA_INDEX_CHASSIS_WAS_OPEN = 36,
55+
HIBDATA_INDEX_FP_LED_LEVEL = 37,
5556
/*
5657
* .. 56 ~ 59 byte for ESPI VW use ..
5758
* .. 60 ~ 63 byte for IMAGETYPE use ..
@@ -368,6 +369,8 @@ static int bbram_idx_lookup(enum system_bbram_idx idx)
368369
return HIBDATA_INDEX_VPRO_STATUS;
369370
case STSTEM_BBRAM_IDX_CHASSIS_WAS_OPEN:
370371
return HIBDATA_INDEX_CHASSIS_WAS_OPEN;
372+
case STSTEM_BBRAM_IDX_FP_LED_LEVEL:
373+
return HIBDATA_INDEX_FP_LED_LEVEL;
371374
default:
372375
return -1;
373376
}

include/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ enum system_bbram_idx {
384384
STSTEM_BBRAM_IDX_CHASSIS_VTR_OPEN,
385385
SYSTEM_BBRAM_IDX_VPRO_STATUS,
386386
STSTEM_BBRAM_IDX_CHASSIS_WAS_OPEN,
387+
STSTEM_BBRAM_IDX_FP_LED_LEVEL,
387388

388389
};
389390

0 commit comments

Comments
 (0)