rk3399: kevin: turn on backlight once EC initializes
authorShelley Chen <shchen@chromium.org>
Mon, 20 Jun 2016 17:07:20 +0000 (10:07 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Thu, 23 Jun 2016 20:11:57 +0000 (13:11 -0700)
After EC finishes initializing, turn on backlight
with host command EC_CMD_PWM_SET_DUTY.

BUG=chrome-os-partner:54389
BRANCH=None
TEST=reboot ec, ap.  See fw screen
     reboot ap only.  See fw screen

Change-Id: Ib84cf8c2de3ce9df82543b35419322fdaa3f5aa8
Signed-off-by: Shelley Chen <shchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/354070
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
src/board/gru/board.c
src/drivers/ec/cros/ec.c
src/drivers/ec/cros/ec.h

index 05ee74a..fa5bce9 100644 (file)
 #include "drivers/storage/dw_mmc.h"
 #include "drivers/storage/rk_dwmmc.h"
 #include "drivers/storage/sdhci.h"
+#include "drivers/video/display.h"
 #include "vboot/util/flag.h"
 
 static const int emmc_sd_clock_min = 400 * 1000;
 static const int emmc_clock_max = 200 * 1000 * 1000;
 
+// Set backlight to 80% by default when on
+// This mirrors default value from the kernel
+// from internal_backlight_no_als_ac_brightness
+#define DEFAULT_EC_BL_PWM_DUTY 80
+
+/*
+ * callback to turn on/off the backlight
+ */
+static int kevin_backlight_update(DisplayOps *me, uint8_t enable)
+{
+       return cros_ec_set_bl_pwm_duty(enable ? DEFAULT_EC_BL_PWM_DUTY : 0);
+}
+
+static DisplayOps kevin_display_ops = {
+       .init = NULL,
+       .backlight_update = &kevin_backlight_update,
+       .stop = NULL,
+};
+
 static int board_setup(void)
 {
        // Claim that we have an open lid to satisfy vboot.
@@ -120,6 +140,11 @@ static int board_setup(void)
 
        ramoops_common_set_buffer();
 
+       // turn on the backlight
+       if (lib_sysinfo.framebuffer &&
+           lib_sysinfo.framebuffer->physical_address)
+               display_set_ops(&kevin_display_ops);
+
        return 0;
 }
 
index 6122f45..dc939d3 100644 (file)
@@ -1116,6 +1116,24 @@ int cros_ec_read_batt_state_of_charge(uint32_t *state)
        return 0;
 }
 
+/*
+ * Set backlight.  Note that duty value needs to be passed
+ * to the EC as a 16 bit number for increased precision.
+ */
+int cros_ec_set_bl_pwm_duty(uint32_t percent)
+{
+       struct ec_params_pwm_set_duty params;
+
+       params.duty = (percent * EC_PWM_MAX_DUTY)/100;
+       params.pwm_type = EC_PWM_TYPE_DISPLAY_LIGHT;
+       params.index = 0;
+
+       if (ec_command(get_main_ec(), EC_CMD_PWM_SET_DUTY, 0,
+                      &params, sizeof(params), NULL, 0) < 0)
+               return -1;
+       return 0;
+}
+
 static int set_max_proto3_sizes(CrosEc *me, int request_size, int response_size)
 {
        free(me->proto3_request);
index 959cf09..74a8bdf 100644 (file)
@@ -247,6 +247,8 @@ int cros_ec_read_batt_state_of_charge(uint32_t *state);
  */
 int cros_ec_read_limit_power_request(int *limit_power);
 
+int cros_ec_set_bl_pwm_duty(uint32_t percent);
+
 CrosEc *new_cros_ec(CrosEcBusOps *bus, int devidx, GpioOps *interrupt_gpio);
 
 #endif