drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness
authorjsg <jsg@openbsd.org>
Mon, 27 Mar 2023 03:27:34 +0000 (03:27 +0000)
committerjsg <jsg@openbsd.org>
Mon, 27 Mar 2023 03:27:34 +0000 (03:27 +0000)
From Daniel Mentz
a64eb25a291904a1736acfd85e5a4e3337f696c2 in linux-6.1.y/6.1.16
c9d27c6be518b4ef2966d9564654ef99292ea1b3 in mainline linux

sys/dev/pci/drm/drm_mipi_dsi.c

index 59bdc36..a8a0796 100644 (file)
@@ -1238,6 +1238,58 @@ int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
 }
 EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness);
 
+/**
+ * mipi_dsi_dcs_set_display_brightness_large() - sets the 16-bit brightness value
+ *    of the display
+ * @dsi: DSI peripheral device
+ * @brightness: brightness value
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi,
+                                            u16 brightness)
+{
+       u8 payload[2] = { brightness >> 8, brightness & 0xff };
+       ssize_t err;
+
+       err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
+                                payload, sizeof(payload));
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness_large);
+
+/**
+ * mipi_dsi_dcs_get_display_brightness_large() - gets the current 16-bit
+ *    brightness value of the display
+ * @dsi: DSI peripheral device
+ * @brightness: brightness value
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
+                                            u16 *brightness)
+{
+       u8 brightness_be[2];
+       ssize_t err;
+
+       err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
+                               brightness_be, sizeof(brightness_be));
+       if (err <= 0) {
+               if (err == 0)
+                       err = -ENODATA;
+
+               return err;
+       }
+
+       *brightness = (brightness_be[0] << 8) | brightness_be[1];
+
+       return 0;
+}
+EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness_large);
+
 static int mipi_dsi_drv_probe(struct device *dev)
 {
        struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);