Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * DSI interface to the Samsung S6E63M0 panel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * (C) 2019 Linus Walleij
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <drm/drm_mipi_dsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <drm/drm_print.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "panel-samsung-s6e63m0.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define MCS_GLOBAL_PARAM	0xb0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define S6E63M0_DSI_MAX_CHUNK	15 /* CMD + 15 bytes max */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static int s6e63m0_dsi_dcs_read(struct device *dev, const u8 cmd, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	ret = mipi_dsi_dcs_read(dsi, cmd, data, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		dev_err(dev, "could not read DCS CMD %02x\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	dev_info(dev, "DSI read CMD %02x = %02x\n", cmd, *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static int s6e63m0_dsi_dcs_write(struct device *dev, const u8 *data, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	const u8 *seqp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u8 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u8 cmdwritten;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	dev_info(dev, "DSI writing dcs seq: %*ph\n", (int)len, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	/* Pick out and skip past the DCS command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	cmd = *seqp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	seqp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	cmdwritten = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	remain = len - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	chunk = remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/* Send max S6E63M0_DSI_MAX_CHUNK bytes at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (chunk > S6E63M0_DSI_MAX_CHUNK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		chunk = S6E63M0_DSI_MAX_CHUNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	ret = mipi_dsi_dcs_write(dsi, cmd, seqp, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		dev_err(dev, "error sending DCS command seq cmd %02x\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	cmdwritten += chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	seqp += chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	while (cmdwritten < remain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		chunk = remain - cmdwritten;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (chunk > S6E63M0_DSI_MAX_CHUNK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			chunk = S6E63M0_DSI_MAX_CHUNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		ret = mipi_dsi_dcs_write(dsi, MCS_GLOBAL_PARAM, &cmdwritten, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			dev_err(dev, "error sending CMD %02x global param %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				cmd, cmdwritten);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		ret = mipi_dsi_dcs_write(dsi, cmd, seqp, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			dev_err(dev, "error sending CMD %02x chunk\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		cmdwritten += chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		seqp += chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	dev_info(dev, "sent command %02x %02x bytes\n", cmd, cmdwritten);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	usleep_range(8000, 9000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int s6e63m0_dsi_probe(struct mipi_dsi_device *dsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct device *dev = &dsi->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	dsi->lanes = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	dsi->format = MIPI_DSI_FMT_RGB888;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	dsi->hs_rate = 349440000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	dsi->lp_rate = 9600000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		MIPI_DSI_MODE_VIDEO_BURST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	ret = s6e63m0_probe(dev, s6e63m0_dsi_dcs_read, s6e63m0_dsi_dcs_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			    true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ret = mipi_dsi_attach(dsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		s6e63m0_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int s6e63m0_dsi_remove(struct mipi_dsi_device *dsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	mipi_dsi_detach(dsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return s6e63m0_remove(&dsi->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static const struct of_device_id s6e63m0_dsi_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	{ .compatible = "samsung,s6e63m0" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) MODULE_DEVICE_TABLE(of, s6e63m0_dsi_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static struct mipi_dsi_driver s6e63m0_dsi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.probe			= s6e63m0_dsi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	.remove			= s6e63m0_dsi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	.driver			= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		.name		= "panel-samsung-s6e63m0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		.of_match_table = s6e63m0_dsi_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) module_mipi_dsi_driver(s6e63m0_dsi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) MODULE_AUTHOR("Linus Walleij <linusw@kernel.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) MODULE_DESCRIPTION("s6e63m0 LCD DSI Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) MODULE_LICENSE("GPL v2");