Skip to content

Commit c9d27c6

Browse files
danielmentzgooglesuperna9999
authored andcommitted
drm/mipi-dsi: Fix byte order of 16-bit 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. Add new functions to properly handle 16-bit brightness in big endian, since the two 8- and 16-bit cases are distinct from each other. [richard: use separate functions instead of switch/case] [richard: split into 16-bit component] Fixes: 1a9d759 ("drm/dsi: Implement DCS set/get display brightness") Signed-off-by: Daniel Mentz <danielmentz@google.com> Link: https://android.googlesource.com/kernel/msm/+/754affd62d0ee268c686c53169b1dbb7deac8550 [richard: fix 16-bit brightness_get] Signed-off-by: Richard Acayan <mailingradian@gmail.com> Tested-by: Caleb Connolly <caleb@connolly.tech> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org> Link: https://patchwork.freedesktop.org/patch/msgid/20230116224909.23884-2-mailingradian@gmail.com
1 parent 13acb36 commit c9d27c6

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

drivers/gpu/drm/drm_mipi_dsi.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,58 @@ int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
12241224
}
12251225
EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness);
12261226

1227+
/**
1228+
* mipi_dsi_dcs_set_display_brightness_large() - sets the 16-bit brightness value
1229+
* of the display
1230+
* @dsi: DSI peripheral device
1231+
* @brightness: brightness value
1232+
*
1233+
* Return: 0 on success or a negative error code on failure.
1234+
*/
1235+
int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi,
1236+
u16 brightness)
1237+
{
1238+
u8 payload[2] = { brightness >> 8, brightness & 0xff };
1239+
ssize_t err;
1240+
1241+
err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
1242+
payload, sizeof(payload));
1243+
if (err < 0)
1244+
return err;
1245+
1246+
return 0;
1247+
}
1248+
EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness_large);
1249+
1250+
/**
1251+
* mipi_dsi_dcs_get_display_brightness_large() - gets the current 16-bit
1252+
* brightness value of the display
1253+
* @dsi: DSI peripheral device
1254+
* @brightness: brightness value
1255+
*
1256+
* Return: 0 on success or a negative error code on failure.
1257+
*/
1258+
int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
1259+
u16 *brightness)
1260+
{
1261+
u8 brightness_be[2];
1262+
ssize_t err;
1263+
1264+
err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
1265+
brightness_be, sizeof(brightness_be));
1266+
if (err <= 0) {
1267+
if (err == 0)
1268+
err = -ENODATA;
1269+
1270+
return err;
1271+
}
1272+
1273+
*brightness = (brightness_be[0] << 8) | brightness_be[1];
1274+
1275+
return 0;
1276+
}
1277+
EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness_large);
1278+
12271279
static int mipi_dsi_drv_probe(struct device *dev)
12281280
{
12291281
struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);

include/drm/drm_mipi_dsi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
296296
u16 brightness);
297297
int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
298298
u16 *brightness);
299+
int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi,
300+
u16 brightness);
301+
int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
302+
u16 *brightness);
299303

300304
/**
301305
* mipi_dsi_generic_write_seq - transmit data using a generic write packet

0 commit comments

Comments
 (0)