diff options
author | xuxinxiong <xuxinxiong@huaqin.corp-partner.google.com> | 2021-10-26 20:16:21 +0800 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2021-11-02 08:17:21 +0000 |
commit | cb3745c407f0c19bfcab06b05549ad20948efff9 (patch) | |
tree | 7894248656ee79559c49bc9cdad7b27a99d9a2ec /src/drivers/parade/ps8640 | |
parent | 73161c644e61e7a6e18ebe0cbb04c573545d1e64 (diff) |
google/trogdor: Add backlight support for Parade ps8640
Add backlight support in ps8640 through the AUX channel using eDP
DPCD registers.
BUG=b:202966352
BRANCH=trogdor
TEST=verified firmware screen works on homestar rev4
Change-Id: Ief1bf56c89c8215427dcbddfc67e8bcd4c3607d2
Signed-off-by: xuxinxiong <xuxinxiong@huaqin.corp-partner.google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/58624
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/drivers/parade/ps8640')
-rw-r--r-- | src/drivers/parade/ps8640/ps8640.c | 100 | ||||
-rw-r--r-- | src/drivers/parade/ps8640/ps8640.h | 28 |
2 files changed, 124 insertions, 4 deletions
diff --git a/src/drivers/parade/ps8640/ps8640.c b/src/drivers/parade/ps8640/ps8640.c index 93121f2094..587eae1d9c 100644 --- a/src/drivers/parade/ps8640/ps8640.c +++ b/src/drivers/parade/ps8640/ps8640.c @@ -5,7 +5,7 @@ #include <edid.h> #include <console/console.h> #include <timer.h> - +#include <dp_aux.h> #include "ps8640.h" int ps8640_get_edid(uint8_t bus, uint8_t chip, struct edid *out) @@ -80,3 +80,101 @@ int ps8640_init(uint8_t bus, uint8_t chip) return 0; } + +static cb_err_t ps8640_bridge_aux_request(uint8_t bus, + uint8_t chip, + unsigned int target_reg, + unsigned int total_size, + enum aux_request request, + uint8_t *data) +{ + int i; + uint32_t length; + uint8_t buf; + uint8_t reg; + int ret; + + if (target_reg & ~SWAUX_ADDR_MASK) + return CB_ERR; + + while (total_size) { + length = MIN(total_size, DP_AUX_MAX_PAYLOAD_BYTES); + total_size -= length; + + ret = i2c_writeb(bus, chip, PAGE0_AUXCH_CFG3, AUXCH_CFG3_RESET); + if (ret) + return CB_ERR; + + enum i2c_over_aux cmd = dp_get_aux_cmd(request, total_size); + if (i2c_writeb(bus, chip, PAGE0_SWAUX_ADDR_23_16, + (target_reg >> 16) | (cmd << 4)) || + i2c_writeb(bus, chip, PAGE0_SWAUX_ADDR_15_8, target_reg >> 8) || + i2c_writeb(bus, chip, PAGE0_SWAUX_ADDR_7_0, target_reg)) { + return CB_ERR; + } + + if (dp_aux_request_is_write(request)) { + reg = PAGE0_SWAUX_WDATA; + for (i = 0; i < length; i++) { + ret = i2c_writeb(bus, chip, reg++, *data++); + if (ret) + return CB_ERR; + } + } else { + if (length == 0) + i2c_writeb(bus, chip, PAGE0_SWAUX_LENGTH, SWAUX_NO_PAYLOAD); + else + i2c_writeb(bus, chip, PAGE0_SWAUX_LENGTH, length - 1); + } + + ret = i2c_writeb(bus, chip, PAGE0_SWAUX_CTRL, SWAUX_SEND); + if (ret) + return CB_ERR; + + if (!wait_ms(100, !i2c_readb(bus, chip, PAGE0_SWAUX_CTRL, &buf) && + !(buf & SWAUX_SEND))) + return CB_ERR; + + if (i2c_readb(bus, chip, PAGE0_SWAUX_STATUS, &buf)) + return CB_ERR; + + switch (buf & SWAUX_STATUS_MASK) { + case SWAUX_STATUS_NACK: + case SWAUX_STATUS_I2C_NACK: + case SWAUX_STATUS_INVALID: + case SWAUX_STATUS_TIMEOUT: + return CB_ERR; + case SWAUX_STATUS_ACKM: + length = buf & SWAUX_M_MASK; + break; + } + + if (length && !dp_aux_request_is_write(request)) { + reg = PAGE0_SWAUX_RDATA; + for (i = 0; i < length; i++) { + if (i2c_readb(bus, chip, reg++, &buf)) + return CB_ERR; + *data++ = buf; + } + } + } + + return CB_SUCCESS; +} + +void ps8640_backlight_enable(uint8_t bus, uint8_t chip) +{ + uint8_t val; + + val = DP_BACKLIGHT_CONTROL_MODE_DPCD; + ps8640_bridge_aux_request(bus, chip, DP_BACKLIGHT_MODE_SET, 1, + DPCD_WRITE, &val); + + val = 0xff; + ps8640_bridge_aux_request(bus, chip, DP_BACKLIGHT_BRIGHTNESS_MSB, 1, + DPCD_WRITE, &val); + + val = DP_BACKLIGHT_ENABLE; + ps8640_bridge_aux_request(bus, chip, DP_DISPLAY_CONTROL_REGISTER, 1, + DPCD_WRITE, &val); +} diff --git a/src/drivers/parade/ps8640/ps8640.h b/src/drivers/parade/ps8640/ps8640.h index 06daad4e3a..fb78be6bd7 100644 --- a/src/drivers/parade/ps8640/ps8640.h +++ b/src/drivers/parade/ps8640/ps8640.h @@ -24,11 +24,33 @@ enum { }; enum { - EDID_LENGTH = 128, - EDID_I2C_ADDR = 0x50, - EDID_EXTENSION_FLAG = 0x7e, + PAGE0_AUXCH_CFG3 = 0x76, + AUXCH_CFG3_RESET = 0xff, + PAGE0_SWAUX_ADDR_7_0 = 0x7d, + PAGE0_SWAUX_ADDR_15_8 = 0x7e, + PAGE0_SWAUX_ADDR_23_16 = 0x7f, + SWAUX_ADDR_MASK = 0xfffff, + PAGE0_SWAUX_LENGTH = 0x80, + SWAUX_LENGTH_MASK = 0xf, + SWAUX_NO_PAYLOAD = BIT(7), + PAGE0_SWAUX_WDATA = 0x81, + PAGE0_SWAUX_RDATA = 0x82, + PAGE0_SWAUX_CTRL = 0x83, + SWAUX_SEND = BIT(0), + PAGE0_SWAUX_STATUS = 0x84, + SWAUX_M_MASK = 0x1f, + SWAUX_STATUS_MASK = (0x7 << 5), + SWAUX_STATUS_NACK = (0x1 << 5), + SWAUX_STATUS_DEFER = (0x2 << 5), + SWAUX_STATUS_ACKM = (0x3 << 5), + SWAUX_STATUS_INVALID = (0x4 << 5), + SWAUX_STATUS_I2C_NACK = (0x5 << 5), + SWAUX_STATUS_I2C_DEFER = (0x6 << 5), + SWAUX_STATUS_TIMEOUT = (0x7 << 5), }; int ps8640_init(uint8_t bus, uint8_t chip); int ps8640_get_edid(uint8_t bus, uint8_t chip, struct edid *out); +void ps8640_backlight_enable(uint8_t bus, uint8_t chip); + #endif |