[Intel-gfx] [PATCH 4/5] drm/i915: Add DCS control for Panel PWM

Deepak M m.deepak at intel.com
Mon Mar 28 09:39:57 UTC 2016


If the source of the backlight PWM is from the
panel then the PWM can be controlled by DCS
command, this patch adds the support to
enable/disbale panel PWM, control backlight level
etc...

v2: Moving the CABC bkl functions to new file.(Jani)

v3: Rebase

v4: Rebase

v5: Use mipi_dsi_dcs_write() instead of mipi_dsi_dcs_write_buffer() (Jani)
    Move DCS macro`s to include/video/mipi_display.h (Jani)

v6: Rename the file to intel_dsi_panel_pwm.c
    Removing the CABC operations

Cc: Jani Nikula <jani.nikula at intel.com>
Cc: Daniel Vetter <daniel.vetter at intel.com>
Cc: Yetunde Adebisi <yetundex.adebisi at intel.com>
Signed-off-by: Deepak M <m.deepak at intel.com>
---

Should this below check be moved to intel_panel.c before calling the
intel_dsi_panel_pwm_init_backlight_funcs() ??
      
	 if (dev_priv->vbt.backlight.pwm_pin ==
                       BLC_CONTROL_PIN_PANEL_PWM)

 drivers/gpu/drm/i915/Makefile              |   1 +
 drivers/gpu/drm/i915/i915_drv.h            |   1 -
 drivers/gpu/drm/i915/intel_drv.h           |   2 +
 drivers/gpu/drm/i915/intel_dsi.c           |  24 ++++-
 drivers/gpu/drm/i915/intel_dsi.h           |   4 +
 drivers/gpu/drm/i915/intel_dsi_panel_pwm.c | 160 +++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_panel.c         |   4 +
 7 files changed, 193 insertions(+), 3 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_dsi_panel_pwm.c

diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 7ffb51b..92abbee 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -83,6 +83,7 @@ i915-y += dvo_ch7017.o \
 	  intel_dp_mst.o \
 	  intel_dp.o \
 	  intel_dsi.o \
+	  intel_dsi_panel_pwm.o \
 	  intel_dsi_panel_vbt.o \
 	  intel_dsi_pll.o \
 	  intel_dvo.o \
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 30321e6..7d6118d 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3491,7 +3491,6 @@ void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
 		     enum intel_sbi_destination destination);
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
-
 int intel_gpu_freq(struct drm_i915_private *dev_priv, int val);
 int intel_freq_opcode(struct drm_i915_private *dev_priv, int val);
 
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 02a74b0..0603c9f 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1330,6 +1330,8 @@ void intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port);
 /* intel_dsi.c */
 void intel_dsi_init(struct drm_device *dev);
 
+/* intel_dsi_panel_pwm.c */
+int intel_dsi_panel_pwm_init_backlight_funcs(struct intel_connector *intel_connector);
 
 /* intel_dvo.c */
 void intel_dvo_init(struct drm_device *dev);
diff --git a/drivers/gpu/drm/i915/intel_dsi.c b/drivers/gpu/drm/i915/intel_dsi.c
index 456676c..1ba757a 100644
--- a/drivers/gpu/drm/i915/intel_dsi.c
+++ b/drivers/gpu/drm/i915/intel_dsi.c
@@ -1209,10 +1209,30 @@ void intel_dsi_init(struct drm_device *dev)
 	else
 		intel_encoder->crtc_mask = BIT(PIPE_B);
 
-	if (dev_priv->vbt.dsi.config->dual_link)
+	if (dev_priv->vbt.dsi.config->dual_link) {
 		intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C);
-	else
+
+		/*
+		 * Based on the VBT value assign the ports on
+		 * which Panel PWM On/OFF DCS coomands needs to be sent
+		 */
+		switch (dev_priv->vbt.dsi.config->dl_panel_pwm_ports) {
+		case PANEL_PWM_PORT_A:
+			intel_dsi->panel_pwm_dcs_ports = BIT(PORT_A);
+			break;
+		case PANEL_PWM_PORT_C:
+			intel_dsi->panel_pwm_dcs_ports = BIT(PORT_C);
+			break;
+		case PANEL_PWM_PORT_A_AND_C:
+			intel_dsi->panel_pwm_dcs_ports = BIT(PORT_A) | BIT(PORT_C);
+			break;
+		default:
+			intel_dsi->panel_pwm_dcs_ports = BIT(PORT_A) | BIT(PORT_C);
+		}
+	} else {
 		intel_dsi->ports = BIT(port);
+		intel_dsi->panel_pwm_dcs_ports = BIT(port);
+	}
 
 	/* Create a DSI host (and a device) for each port. */
 	for_each_dsi_port(port, intel_dsi->ports) {
diff --git a/drivers/gpu/drm/i915/intel_dsi.h b/drivers/gpu/drm/i915/intel_dsi.h
index f54748d..dcd2265 100644
--- a/drivers/gpu/drm/i915/intel_dsi.h
+++ b/drivers/gpu/drm/i915/intel_dsi.h
@@ -34,6 +34,10 @@
 #define DSI_DUAL_LINK_FRONT_BACK	1
 #define DSI_DUAL_LINK_PIXEL_ALT		2
 
+#define PANEL_PWM_PORT_A		0x00
+#define PANEL_PWM_PORT_C		0x01
+#define PANEL_PWM_PORT_A_AND_C		0x02
+
 struct intel_dsi_host;
 
 struct intel_dsi {
diff --git a/drivers/gpu/drm/i915/intel_dsi_panel_pwm.c b/drivers/gpu/drm/i915/intel_dsi_panel_pwm.c
new file mode 100644
index 0000000..4d7f0eb
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_dsi_panel_pwm.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Deepak M <m.deepak at intel.com>
+ */
+
+#include "intel_drv.h"
+#include "intel_dsi.h"
+#include "i915_drv.h"
+#include <video/mipi_display.h>
+#include <drm/drm_mipi_dsi.h>
+
+#define PANEL_PWM_BKL_EN		(1 << 2)
+#define PANEL_PWM_DISP_DIMMING		(1 << 3)
+#define PANEL_PWM_BCTRL			(1 << 5)
+
+#define PANEL_PWM_MAX_VALUE		0xFF
+
+static u32 panel_pwm_get_backlight(struct intel_connector *connector)
+{
+	struct intel_encoder *encoder = connector->encoder;
+	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
+	struct mipi_dsi_device *dsi_device;
+	u8 data;
+	enum port port;
+
+	/* FIXME Need to take care of 16 bit brightness level */
+	/*
+	 * Sending the DCS commands to the ports to which Panel PWM
+	 * On/Off commands were send
+	 */
+	for_each_dsi_port(port, intel_dsi->panel_pwm_dcs_ports) {
+		dsi_device = intel_dsi->dsi_hosts[port]->device;
+		mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
+					&data, sizeof(data));
+		break;
+	}
+
+	return data;
+}
+
+static void panel_pwm_set_backlight(struct intel_connector *connector, u32 level)
+{
+	struct intel_encoder *encoder = connector->encoder;
+	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
+	struct mipi_dsi_device *dsi_device;
+	u8 data;
+	enum port port;
+
+	/* FIXME Need to take care of 16 bit brightness level */
+	/*
+	 * Sending the DCS commands to the ports to which Panel PWM
+	 * On/Off commands were send
+	 */
+	for_each_dsi_port(port, intel_dsi->panel_pwm_dcs_ports) {
+		dsi_device = intel_dsi->dsi_hosts[port]->device;
+		data = level;
+		mipi_dsi_dcs_write(dsi_device, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
+					&data, sizeof(data));
+	}
+}
+
+static void panel_pwm_disable_backlight(struct intel_connector *connector)
+{
+	struct intel_encoder *encoder = connector->encoder;
+	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
+	struct mipi_dsi_device *dsi_device;
+	enum port port;
+	u8 data;
+
+	panel_pwm_set_backlight(connector, 0);
+
+	for_each_dsi_port(port, intel_dsi->panel_pwm_dcs_ports) {
+		dsi_device = intel_dsi->dsi_hosts[port]->device;
+		data &= ~PANEL_PWM_BKL_EN; /* Turn Off Backlight */
+		data &= ~PANEL_PWM_DISP_DIMMING; /* Display Dimming Off */
+		data &= ~PANEL_PWM_BCTRL; /* Brightness control Block Off */
+		mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_CONTROL_DISPLAY,
+					&data, sizeof(data));
+	}
+}
+
+static void panel_pwm_enable_backlight(struct intel_connector *connector)
+{
+	struct intel_encoder *encoder = connector->encoder;
+	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
+	struct intel_panel *panel = &connector->panel;
+	struct mipi_dsi_device *dsi_device;
+	enum port port;
+	u8 data;
+
+	for_each_dsi_port(port, intel_dsi->panel_pwm_dcs_ports) {
+		dsi_device = intel_dsi->dsi_hosts[port]->device;
+		data = PANEL_PWM_BKL_EN /* Turn on backlight */
+			| PANEL_PWM_DISP_DIMMING /* Display Dimming On */
+			| PANEL_PWM_BCTRL; /* Brightness control Block On */
+		mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_CONTROL_DISPLAY,
+					&data, sizeof(data));
+	}
+
+	panel_pwm_set_backlight(connector, panel->backlight.level);
+}
+
+static int panel_pwm_setup_backlight(struct intel_connector *connector,
+		enum pipe unused)
+{
+	struct intel_panel *panel = &connector->panel;
+
+	panel->backlight.max = PANEL_PWM_MAX_VALUE;
+	/* Assigning the MAX value during the setup */
+	panel->backlight.level = PANEL_PWM_MAX_VALUE;
+
+	return 0;
+}
+
+int intel_dsi_panel_pwm_init_backlight_funcs(struct intel_connector *intel_connector)
+{
+	struct drm_device *dev = intel_connector->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct intel_encoder *encoder = intel_connector->encoder;
+	struct intel_panel *panel = &intel_connector->panel;
+
+	/*
+	 * Continue initalizing only if the PWM source is
+	 * from the panel
+	 */
+	if (dev_priv->vbt.backlight.pwm_pin !=
+			BLC_CONTROL_PIN_PANEL_PWM)
+		return -ENODEV;
+
+	if (WARN_ON(encoder->type != INTEL_OUTPUT_DSI))
+		return -EINVAL;
+
+	panel->backlight.setup = panel_pwm_setup_backlight;
+	panel->backlight.enable = panel_pwm_enable_backlight;
+	panel->backlight.disable = panel_pwm_disable_backlight;
+	panel->backlight.set = panel_pwm_set_backlight;
+	panel->backlight.get = panel_pwm_get_backlight;
+
+	return 0;
+}
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index 8c8996f..46ca2de 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -1718,6 +1718,10 @@ intel_panel_init_backlight_funcs(struct intel_panel *panel)
 		container_of(panel, struct intel_connector, panel);
 	struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
 
+	if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI &&
+		intel_dsi_panel_pwm_init_backlight_funcs(connector) == 0)
+		return;
+
 	if (IS_BROXTON(dev_priv)) {
 		panel->backlight.setup = bxt_setup_backlight;
 		panel->backlight.enable = bxt_enable_backlight;
-- 
1.9.1



More information about the Intel-gfx mailing list