Commit 435e06c0 authored by Linus Walleij's avatar Linus Walleij
Browse files

drm/panel: s6e63m0: Add DSI transport



This makes it possible to use the s6e63m0 panel with a
DSI host, such as in the Samsung GT-I8190 (Golden) mobile
phone.

Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Tested-by: default avatarStephan Gerhold <stephan@gerhold.net>
Cc: Stephan Gerhold <stephan@gerhold.net>
Cc: Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>
Acked-by: default avatarPaul Cercueil <paul@crapouillou.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20200809215104.1830206-3-linus.walleij@linaro.org
parent b7b23e44
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -341,6 +341,14 @@ config DRM_PANEL_SAMSUNG_S6E63M0_SPI
	  Say Y here if you want to be able to access the Samsung
	  S6E63M0 panel using SPI.

config DRM_PANEL_SAMSUNG_S6E63M0_DSI
	tristate "Samsung S6E63M0 RGB DSI interface"
	depends on DRM_MIPI_DSI
	depends on DRM_PANEL_SAMSUNG_S6E63M0
	help
	  Say Y here if you want to be able to access the Samsung
	  S6E63M0 panel using DSI.

config DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01
	tristate "Samsung AMS452EF01 panel with S6E88A0 DSI video mode controller"
	depends on OF
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3HA2) += panel-samsung-s6e3ha2.o
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63J0X03) += panel-samsung-s6e63j0x03.o
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63M0) += panel-samsung-s6e63m0.o
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63M0_SPI) += panel-samsung-s6e63m0-spi.o
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63M0_DSI) += panel-samsung-s6e63m0-dsi.o
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams452ef01.o
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o
obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o
+128 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * DSI interface to the Samsung S6E63M0 panel.
 * (C) 2019 Linus Walleij
 */

#include <linux/module.h>
#include <linux/delay.h>
#include <linux/of_device.h>

#include <drm/drm_mipi_dsi.h>
#include <drm/drm_print.h>

#include "panel-samsung-s6e63m0.h"

#define MCS_GLOBAL_PARAM	0xb0
#define S6E63M0_DSI_MAX_CHUNK	15 /* CMD + 15 bytes max */

static int s6e63m0_dsi_dcs_write(struct device *dev, const u8 *data, size_t len)
{
	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
	const u8 *seqp = data;
	u8 cmd;
	u8 cmdwritten;
	int remain;
	int chunk;
	int ret;

	DRM_DEV_INFO(dev, "DSI writing dcs seq: %*ph\n", (int)len, data);

	/* Pick out and skip past the DCS command */
	cmd = *seqp;
	seqp++;
	cmdwritten = 0;
	remain = len - 1;
	chunk = remain;

	/* Send max S6E63M0_DSI_MAX_CHUNK bytes at a time */
	if (chunk > S6E63M0_DSI_MAX_CHUNK)
		chunk = S6E63M0_DSI_MAX_CHUNK;
	ret = mipi_dsi_dcs_write(dsi, cmd, seqp, chunk);
	if (ret < 0) {
		DRM_DEV_ERROR(dev,
			      "error sending DCS command seq cmd %02x\n",
			      cmd);
		return ret;
	}
	cmdwritten += chunk;
	seqp += chunk;

	while (cmdwritten < remain) {
		chunk = remain - cmdwritten;
		if (chunk > S6E63M0_DSI_MAX_CHUNK)
			chunk = S6E63M0_DSI_MAX_CHUNK;
		ret = mipi_dsi_dcs_write(dsi, MCS_GLOBAL_PARAM, &cmdwritten, 1);
		if (ret < 0) {
			DRM_DEV_ERROR(dev,
				      "error sending CMD %02x global param %02x\n",
				      cmd, cmdwritten);
			return ret;
		}
		ret = mipi_dsi_dcs_write(dsi, cmd, seqp, chunk);
		if (ret < 0) {
			DRM_DEV_ERROR(dev,
				      "error sending CMD %02x chunk\n",
				      cmd);
			return ret;
		}
		cmdwritten += chunk;
		seqp += chunk;
	}
	DRM_DEV_INFO(dev, "sent command %02x %02x bytes\n",
		     cmd, cmdwritten);

	usleep_range(8000, 9000);

	return 0;
}

static int s6e63m0_dsi_probe(struct mipi_dsi_device *dsi)
{
	struct device *dev = &dsi->dev;
	int ret;

	dsi->lanes = 2;
	dsi->format = MIPI_DSI_FMT_RGB888;
	dsi->hs_rate = 349440000;
	dsi->lp_rate = 9600000;
	dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
		MIPI_DSI_MODE_EOT_PACKET |
		MIPI_DSI_MODE_VIDEO_BURST;

	ret = s6e63m0_probe(dev, s6e63m0_dsi_dcs_write, true);
	if (ret)
		return ret;

	ret = mipi_dsi_attach(dsi);
	if (ret < 0)
		s6e63m0_remove(dev);

	return ret;
}

static int s6e63m0_dsi_remove(struct mipi_dsi_device *dsi)
{
	mipi_dsi_detach(dsi);
	return s6e63m0_remove(&dsi->dev);
}

static const struct of_device_id s6e63m0_dsi_of_match[] = {
	{ .compatible = "samsung,s6e63m0" },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, s6e63m0_dsi_of_match);

static struct mipi_dsi_driver s6e63m0_dsi_driver = {
	.probe			= s6e63m0_dsi_probe,
	.remove			= s6e63m0_dsi_remove,
	.driver			= {
		.name		= "panel-samsung-s6e63m0",
		.of_match_table = s6e63m0_dsi_of_match,
	},
};
module_mipi_dsi_driver(s6e63m0_dsi_driver);

MODULE_AUTHOR("Linus Walleij <linusw@kernel.org>");
MODULE_DESCRIPTION("s6e63m0 LCD DSI Driver");
MODULE_LICENSE("GPL v2");
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ static int s6e63m0_spi_probe(struct spi_device *spi)
		DRM_DEV_ERROR(dev, "spi setup failed.\n");
		return ret;
	}
	return s6e63m0_probe(dev, s6e63m0_spi_dcs_write);
	return s6e63m0_probe(dev, s6e63m0_spi_dcs_write, false);
}

static int s6e63m0_spi_remove(struct spi_device *spi)
+3 −1
Original line number Diff line number Diff line
@@ -400,7 +400,8 @@ static int s6e63m0_backlight_register(struct s6e63m0 *ctx)
}

int s6e63m0_probe(struct device *dev,
		  int (*dcs_write)(struct device *dev, const u8 *data, size_t len))
		  int (*dcs_write)(struct device *dev, const u8 *data, size_t len),
		  bool dsi_mode)
{
	struct s6e63m0 *ctx;
	int ret;
@@ -432,6 +433,7 @@ int s6e63m0_probe(struct device *dev,
	}

	drm_panel_init(&ctx->panel, dev, &s6e63m0_drm_funcs,
		       dsi_mode ? DRM_MODE_CONNECTOR_DSI :
		       DRM_MODE_CONNECTOR_DPI);

	ret = s6e63m0_backlight_register(ctx);
Loading