Re: [PATCH V5 3/4] drm/panel: Add Magnachip D53E6EA8966 Panel Driver

2022-12-15 Thread Linus Walleij
Hi Chris,

looks good to me, just very minor nitpicks:

On Wed, Dec 14, 2022 at 7:06 PM Chris Morgan  wrote:
>
> From: Chris Morgan 
>
> Support Magnachip D53E6EA8966 based panels such as the Samsung
> AMS495QA01 panel as found on the Anbernic RG503. Note this driver
> supports only the AMS495QA01 today which receives video signals via DSI,
> however it receives commands via 3-wire SPI.

using DBI.

>
> Signed-off-by: Chris Morgan 
> Signed-off-by: Maya Matuszczyk 

Is your Kconfig snippet missing:

depends on BACKLIGHT_CLASS_DEVICE

?

> +#include 
> +#include 

Not needed anymore, right?

With these fixed:
Reviewed-by: Linus Walleij 

Yours,
Linus Walleij


[PATCH V5 3/4] drm/panel: Add Magnachip D53E6EA8966 Panel Driver

2022-12-14 Thread Chris Morgan
From: Chris Morgan 

Support Magnachip D53E6EA8966 based panels such as the Samsung
AMS495QA01 panel as found on the Anbernic RG503. Note this driver
supports only the AMS495QA01 today which receives video signals via DSI,
however it receives commands via 3-wire SPI.

Signed-off-by: Chris Morgan 
Signed-off-by: Maya Matuszczyk 
---
 drivers/gpu/drm/panel/Kconfig |  10 +
 drivers/gpu/drm/panel/Makefile|   1 +
 .../drm/panel/panel-magnachip-d53e6ea8966.c   | 515 ++
 3 files changed, 526 insertions(+)
 create mode 100644 drivers/gpu/drm/panel/panel-magnachip-d53e6ea8966.c

diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index a582ddd583c2..1f81fe8a2f8a 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -288,6 +288,16 @@ config DRM_PANEL_LG_LG4573
  Say Y here if you want to enable support for LG4573 RGB panel.
  To compile this driver as a module, choose M here.
 
+config DRM_PANEL_MAGNACHIP_D53E6EA8966
+   tristate "Magnachip D53E6EA8966 DSI panel"
+   depends on OF && SPI
+   depends on DRM_MIPI_DSI
+   select DRM_MIPI_DBI
+   help
+ DRM panel driver for the Samsung AMS495QA01 panel controlled
+ with the Magnachip D53E6EA8966 panel IC. This panel receives
+ video data via DSI but commands via 3-Wire 9-bit SPI.
+
 config DRM_PANEL_NEC_NL8048HL11
tristate "NEC NL8048HL11 RGB panel"
depends on GPIOLIB && OF && SPI
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index 34e717382dbb..7c09cd480c69 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK050H3146W) += 
panel-leadtek-ltk050h3146w.o
 obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829) += panel-leadtek-ltk500hd1829.o
 obj-$(CONFIG_DRM_PANEL_LG_LB035Q02) += panel-lg-lb035q02.o
 obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
+obj-$(CONFIG_DRM_PANEL_MAGNACHIP_D53E6EA8966) += panel-magnachip-d53e6ea8966.o
 obj-$(CONFIG_DRM_PANEL_NEC_NL8048HL11) += panel-nec-nl8048hl11.o
 obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3051D) += panel-newvision-nv3051d.o
 obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3052C) += panel-newvision-nv3052c.o
diff --git a/drivers/gpu/drm/panel/panel-magnachip-d53e6ea8966.c 
b/drivers/gpu/drm/panel/panel-magnachip-d53e6ea8966.c
new file mode 100644
index ..c1b80f2f296c
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-magnachip-d53e6ea8966.c
@@ -0,0 +1,515 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Magnachip d53e6ea8966 MIPI-DSI panel driver
+ * Copyright (C) 2022 Chris Morgan
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/* Forward declaration for use in backlight function */
+struct d53e6ea8966;
+
+/* Panel info, unique to each panel */
+struct d53e6ea8966_panel_info {
+   /** @display_modes: the supported display modes */
+   const struct drm_display_mode *display_modes;
+   /** @num_modes: the number of supported display modes */
+   unsigned int num_modes;
+   /** @width_mm: panel width in mm */
+   u16 width_mm;
+   /** @height_mm: panel height in mm */
+   u16 height_mm;
+   /** @bus_flags: drm bus flags for panel */
+   u32 bus_flags;
+   /** @panel_funcs: panel functions for panel */
+   const struct drm_panel_funcs *panel_funcs;
+   /** @backlight: panel backlight registration or NULL */
+   int (*backlight_register)(struct d53e6ea8966 *db);
+};
+
+struct d53e6ea8966 {
+   /** @dev: the container device */
+   struct device *dev;
+   /** @dbi: the DBI bus abstraction handle */
+   struct mipi_dbi dbi;
+   /** @panel: the DRM panel instance for this device */
+   struct drm_panel panel;
+   /** @reset: reset GPIO line */
+   struct gpio_desc *reset;
+   /** @enable: enable GPIO line */
+   struct gpio_desc *enable;
+   /** @reg_vdd: VDD supply regulator for panel logic */
+   struct regulator *reg_vdd;
+   /** @reg_elvdd: ELVDD supply regulator for panel display */
+   struct regulator *reg_elvdd;
+   /** @dsi_dev: DSI child device (panel) */
+   struct mipi_dsi_device *dsi_dev;
+   /** @bl_dev: pseudo-backlight device for oled panel */
+   struct backlight_device *bl_dev;
+   /** @panel_info: struct containing panel timing and info */
+   const struct d53e6ea8966_panel_info *panel_info;
+};
+
+#define NUM_GAMMA_LEVELS   16
+#define GAMMA_TABLE_COUNT  23
+#define MAX_BRIGHTNESS (NUM_GAMMA_LEVELS - 1)
+
+#define MCS_ELVSS_ON   0xb1
+#define MCS_TEMP_SWIRE 0xb2
+#define MCS_PASSWORD_0 0xf0
+#define MCS_PASSWORD_1 0xf1
+#define MCS_ANALOG_PWR_CTL_0   0xf4
+#define