[PATCH 1/3] drm/dsi: Add support for Turn on/Shutdown peripheral packets

2015-10-30 Thread bj...@kryo.se
From: Werner Johansson 

The MIPI_DSI_TURN_ON_PERIPHERAL and MIPI_DSI_SHUTDOWN_PERIPHERAL
packets are required for some panels, one example being the
Panasonic VVX10F034N00 panel.

Signed-off-by: Werner Johansson 
Signed-off-by: Bjorn Andersson 
---
 drivers/gpu/drm/drm_mipi_dsi.c | 47 ++
 include/drm/drm_mipi_dsi.h |  3 +++
 2 files changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 2d5ca8ee..13b4a9c 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -862,6 +862,53 @@ int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device 
*dsi, u8 format)
 }
 EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format);

+/**
+ * mipi_dsi_raw_short_write() - Sends a data-less short DSI packet
+ * @dsi: DSI peripheral device
+ * @type: Data Type of packet to send
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+static ssize_t mipi_dsi_raw_short_write(struct mipi_dsi_device *dsi, u8 type)
+{
+   u8 dummy[2] = { 0, 0 };
+   struct mipi_dsi_msg msg = {
+   .channel = dsi->channel,
+   .tx_buf = dummy,
+   .tx_len = sizeof(dummy),
+   .type = type
+   };
+
+   if (mipi_dsi_packet_format_is_short(type))
+   return mipi_dsi_device_transfer(dsi, &msg);
+   else
+   return -1;
+}
+
+/**
+ * mipi_dsi_turn_on_peripheral() - Sends Turn On Peripheral DSI command
+ * @dsi: DSI peripheral device
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+ssize_t mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
+{
+   return mipi_dsi_raw_short_write(dsi, MIPI_DSI_TURN_ON_PERIPHERAL);
+}
+EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
+
+/**
+ * mipi_dsi_shutdown_peripheral() - Sends Shutdown Peripheral DSI command
+ * @dsi: DSI peripheral device
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+ssize_t mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
+{
+   return mipi_dsi_raw_short_write(dsi, MIPI_DSI_SHUTDOWN_PERIPHERAL);
+}
+EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
+
 static int mipi_dsi_drv_probe(struct device *dev)
 {
struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
index f1d8d0d..2e0f057 100644
--- a/include/drm/drm_mipi_dsi.h
+++ b/include/drm/drm_mipi_dsi.h
@@ -215,6 +215,9 @@ int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
 enum mipi_dsi_dcs_tear_mode mode);
 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);

+ssize_t mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
+ssize_t mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
+
 /**
  * struct mipi_dsi_driver - DSI driver
  * @driver: device driver model driver
-- 
2.3.2 (Apple Git-55)



[PATCH 2/3] panel/panasonic-vvx10f034n00: Add DT bindings

2015-10-30 Thread bj...@kryo.se
From: Werner Johansson 

This patch adds bindings for the Panasonic VVX10F034N00
WUXGA panel.

Signed-off-by: Werner Johansson 
Signed-off-by: Bjorn Andersson 
---
 .../bindings/panel/panasonic,vvx10f034n00.txt| 20 
 1 file changed, 20 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/panel/panasonic,vvx10f034n00.txt

diff --git a/Documentation/devicetree/bindings/panel/panasonic,vvx10f034n00.txt 
b/Documentation/devicetree/bindings/panel/panasonic,vvx10f034n00.txt
new file mode 100644
index 000..37dedf6
--- /dev/null
+++ b/Documentation/devicetree/bindings/panel/panasonic,vvx10f034n00.txt
@@ -0,0 +1,20 @@
+Panasonic 10" WUXGA TFT LCD panel
+
+Required properties:
+- compatible: should be "panasonic,vvx10f034n00"
+- reg: DSI virtual channel of the peripheral
+- power-supply: phandle of the regulator that provides the supply voltage
+
+Optional properties:
+- backlight: phandle of the backlight device attached to the panel
+
+Example:
+
+   mdss_dsi at fd922800 {
+   panel at 0 {
+   compatible = "panasonic,vvx10f034n00";
+   reg = <0>;
+   power-supply = <&vreg_vsp>;
+   backlight = <&lp8566_wled>;
+   };
+   };
-- 
2.3.2 (Apple Git-55)



[PATCH 3/3] drm/panel: Add Panasonic VVX10F034N00 MIPI DSI panel

2015-10-30 Thread bj...@kryo.se
From: Werner Johansson 

This adds support for the Panasonic panel found in some Xperia Z2
tablets.

Signed-off-by: Werner Johansson 
Signed-off-by: Bjorn Andersson 
---
 drivers/gpu/drm/panel/Kconfig  |  10 +
 drivers/gpu/drm/panel/Makefile |   1 +
 .../gpu/drm/panel/panel-panasonic-vvx10f034n00.c   | 334 +
 3 files changed, 345 insertions(+)
 create mode 100644 drivers/gpu/drm/panel/panel-panasonic-vvx10f034n00.c

diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 7d4704b..77a20d6 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -51,4 +51,14 @@ config DRM_PANEL_SHARP_LQ101R1SX01
  To compile this driver as a module, choose M here: the module
  will be called panel-sharp-lq101r1sx01.

+config DRM_PANEL_PANASONIC_VVX10F034N00
+   tristate "Panasonic VVX10F034N00 1920x1200 video mode panel"
+   depends on OF
+   depends on DRM_MIPI_DSI
+   depends on BACKLIGHT_CLASS_DEVICE
+   help
+ Say Y here if you want to enable support for Panasonic VVX10F034N00
+ WUXGA (1920x1200) Novatek NT1397-based DSI panel as found in some
+ Xperia Z2 tablets
+
 endmenu
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index d0f016d..a2ca8ff 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
 obj-$(CONFIG_DRM_PANEL_SAMSUNG_LD9040) += panel-samsung-ld9040.o
 obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o
 obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o
+obj-$(CONFIG_DRM_PANEL_PANASONIC_VVX10F034N00) += 
panel-panasonic-vvx10f034n00.o
diff --git a/drivers/gpu/drm/panel/panel-panasonic-vvx10f034n00.c 
b/drivers/gpu/drm/panel/panel-panasonic-vvx10f034n00.c
new file mode 100644
index 000..7f915f7
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-panasonic-vvx10f034n00.c
@@ -0,0 +1,334 @@
+/*
+ * Copyright (C) 2015 Red Hat
+ * Copyright (C) 2015 Sony Mobile Communications Inc.
+ * Author: Werner Johansson 
+ *
+ * Based on AUO panel driver by Rob Clark 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/*
+ * When power is turned off to this panel a minimum off time of 500ms has to be
+ * observed before powering back on as there's no external reset pin. Keep
+ * track of earliest wakeup time and delay subsequent prepare call accordingly
+ */
+#define MIN_POFF_MS (500)
+
+struct wuxga_nt_panel {
+   struct drm_panel base;
+   struct mipi_dsi_device *dsi;
+
+   struct backlight_device *backlight;
+   struct regulator *supply;
+
+   bool prepared;
+   bool enabled;
+
+   ktime_t earliest_wake;
+
+   const struct drm_display_mode *mode;
+};
+
+static inline struct wuxga_nt_panel *to_wuxga_nt_panel(struct drm_panel *panel)
+{
+   return container_of(panel, struct wuxga_nt_panel, base);
+}
+
+static int wuxga_nt_panel_on(struct wuxga_nt_panel *wuxga_nt)
+{
+   struct mipi_dsi_device *dsi = wuxga_nt->dsi;
+   int ret;
+
+   ret = mipi_dsi_turn_on_peripheral(dsi);
+   if (ret < 0)
+   return ret;
+
+   return 0;
+}
+
+static int wuxga_nt_panel_disable(struct drm_panel *panel)
+{
+   struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
+
+   if (!wuxga_nt->enabled)
+   return 0;
+
+   mipi_dsi_shutdown_peripheral(wuxga_nt->dsi);
+
+   if (wuxga_nt->backlight) {
+   wuxga_nt->backlight->props.power = FB_BLANK_POWERDOWN;
+   wuxga_nt->backlight->props.state |= BL_CORE_FBBLANK;
+   backlight_update_status(wuxga_nt->backlight);
+   }
+
+   wuxga_nt->enabled = false;
+
+   return 0;
+}
+
+static int wuxga_nt_panel_unprepare(struct drm_panel *panel)
+{
+   struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
+
+   if (!wuxga_nt->prepared)
+   return 0;
+
+   regulator_disable(wuxga_nt->supply);
+   wuxga_nt->earliest_wake = ktime_add_ms(ktime_get_real(), MIN_POFF_MS);
+   wuxga_nt->prepared = false;
+
+   return 0;
+}
+
+static int wuxga_nt_panel_prepare(struct drm_panel *panel)
+{
+   struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
+   int ret