From 8a744ca6639cddce26d48c120c735d5a19656227 Mon Sep 17 00:00:00 2001 From: Daniel Mentz Date: Mon, 23 Oct 2017 19:55:56 -0700 Subject: [PATCH] ANDROID: drm/dsi: Fix byte order of DCS set/get brightness The MIPI DCS specification demands that brightness values are sent in big endian byte order. It also states that one parameter (i.e. one byte) shall be sent/received for 8 bit wide values, and two parameters shall be used for values that are between 9 and 16 bits wide. Bug: 139263611 Bug: 139107810 Change-Id: I24306e21ec6a5ff48ea121d977419a81d5b44152 Signed-off-by: Daniel Mentz Signed-off-by: Wilson Sung (cherry picked from commit 3c373bfd83fd686390ea60a032ff876242c71d49) Signed-off-by: Saravana Kannan --- drivers/gpu/drm/drm_mipi_dsi.c | 44 ++++++++++++++++--- .../gpu/drm/panel/panel-jdi-lt070me05000.c | 4 +- .../gpu/drm/panel/panel-samsung-s6e63j0x03.c | 2 +- include/drm/drm_mipi_dsi.h | 4 +- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index 81685a804250..e730c6d26bd2 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -1052,17 +1052,33 @@ EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_scanline); * display * @dsi: DSI peripheral device * @brightness: brightness value + * @num_params: Number of parameters (bytes) to encode brightness value in. The + * MIPI specification states that one parameter shall be sent for + * devices that support 8-bit brightness levels. For devices that + * support brightness levels wider than 8-bit, two parameters + * shall be sent. * * Return: 0 on success or a negative error code on failure. */ int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi, - u16 brightness) + u16 brightness, size_t num_params) { - u8 payload[2] = { brightness & 0xff, brightness >> 8 }; + u8 payload[2]; ssize_t err; + switch (num_params) { + case 1: + payload[0] = brightness & 0xff; + break; + case 2: + payload[0] = brightness >> 8; + payload[1] = brightness & 0xff; + break; + default: + return -EINVAL; + } err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS, - payload, sizeof(payload)); + payload, num_params); if (err < 0) return err; @@ -1075,16 +1091,25 @@ EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness); * of the display * @dsi: DSI peripheral device * @brightness: brightness value + * @num_params: Number of parameters (i.e. bytes) the brightness value is + * encoded in. The MIPI specification states that one parameter + * shall be returned from devices that support 8-bit brightness + * levels. Devices that support brightness levels wider than + * 8-bit return two parameters (i.e. bytes). * * Return: 0 on success or a negative error code on failure. */ int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi, - u16 *brightness) + u16 *brightness, size_t num_params) { + u8 payload[2]; ssize_t err; + if (!(num_params == 1 || num_params == 2)) + return -EINVAL; + err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS, - brightness, sizeof(*brightness)); + payload, num_params); if (err <= 0) { if (err == 0) err = -ENODATA; @@ -1092,6 +1117,15 @@ int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi, return err; } + switch (num_params) { + case 1: + *brightness = payload[0]; + break; + case 2: + *brightness = payload[0] << 8 || payload[1]; + break; + } + return 0; } EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness); diff --git a/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c b/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c index 99caa7835e7b..5d21f7b6ba92 100644 --- a/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c +++ b/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c @@ -341,7 +341,7 @@ static int dsi_dcs_bl_get_brightness(struct backlight_device *bl) dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; - ret = mipi_dsi_dcs_get_display_brightness(dsi, &brightness); + ret = mipi_dsi_dcs_get_display_brightness(dsi, &brightness, 1); if (ret < 0) return ret; @@ -357,7 +357,7 @@ static int dsi_dcs_bl_update_status(struct backlight_device *bl) dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; - ret = mipi_dsi_dcs_set_display_brightness(dsi, bl->props.brightness); + ret = mipi_dsi_dcs_set_display_brightness(dsi, bl->props.brightness, 1); if (ret < 0) return ret; diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e63j0x03.c b/drivers/gpu/drm/panel/panel-samsung-s6e63j0x03.c index aeb32aa58899..7e047aa7d20f 100644 --- a/drivers/gpu/drm/panel/panel-samsung-s6e63j0x03.c +++ b/drivers/gpu/drm/panel/panel-samsung-s6e63j0x03.c @@ -365,7 +365,7 @@ static int s6e63j0x03_enable(struct drm_panel *panel) return ret; /* set default white brightness */ - ret = mipi_dsi_dcs_set_display_brightness(dsi, 0x00ff); + ret = mipi_dsi_dcs_set_display_brightness(dsi, 0x00ff, 1); if (ret < 0) return ret; diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h index 328f232f33ee..b208412dd52d 100644 --- a/include/drm/drm_mipi_dsi.h +++ b/include/drm/drm_mipi_dsi.h @@ -283,9 +283,9 @@ int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi, int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format); int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline); int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi, - u16 brightness); + u16 brightness, size_t num_params); int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi, - u16 *brightness); + u16 *brightness, size_t num_params); /** * struct mipi_dsi_driver - DSI driver