1 // SPDX-License-Identifier: GPL-2.0
3 * DSI interface to the Samsung S6E63M0 panel.
4 * (C) 2019 Linus Walleij
7 #include <linux/module.h>
8 #include <linux/delay.h>
9 #include <linux/of_device.h>
11 #include <drm/drm_mipi_dsi.h>
12 #include <drm/drm_print.h>
14 #include "panel-samsung-s6e63m0.h"
16 #define MCS_GLOBAL_PARAM 0xb0
17 #define S6E63M0_DSI_MAX_CHUNK 15 /* CMD + 15 bytes max */
19 static int s6e63m0_dsi_dcs_read(struct device *dev, void *trsp,
20 const u8 cmd, u8 *data)
22 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
25 ret = mipi_dsi_dcs_read(dsi, cmd, data, 1);
27 dev_err(dev, "could not read DCS CMD %02x\n", cmd);
31 dev_dbg(dev, "DSI read CMD %02x = %02x\n", cmd, *data);
36 static int s6e63m0_dsi_dcs_write(struct device *dev, void *trsp,
37 const u8 *data, size_t len)
39 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
40 const u8 *seqp = data;
47 dev_dbg(dev, "DSI writing dcs seq: %*ph\n", (int)len, data);
49 /* Pick out and skip past the DCS command */
56 /* Send max S6E63M0_DSI_MAX_CHUNK bytes at a time */
57 if (chunk > S6E63M0_DSI_MAX_CHUNK)
58 chunk = S6E63M0_DSI_MAX_CHUNK;
59 ret = mipi_dsi_dcs_write(dsi, cmd, seqp, chunk);
61 dev_err(dev, "error sending DCS command seq cmd %02x\n", cmd);
67 while (cmdwritten < remain) {
68 chunk = remain - cmdwritten;
69 if (chunk > S6E63M0_DSI_MAX_CHUNK)
70 chunk = S6E63M0_DSI_MAX_CHUNK;
71 ret = mipi_dsi_dcs_write(dsi, MCS_GLOBAL_PARAM, &cmdwritten, 1);
73 dev_err(dev, "error sending CMD %02x global param %02x\n",
77 ret = mipi_dsi_dcs_write(dsi, cmd, seqp, chunk);
79 dev_err(dev, "error sending CMD %02x chunk\n", cmd);
85 dev_dbg(dev, "sent command %02x %02x bytes\n", cmd, cmdwritten);
87 usleep_range(8000, 9000);
92 static int s6e63m0_dsi_probe(struct mipi_dsi_device *dsi)
94 struct device *dev = &dsi->dev;
98 dsi->format = MIPI_DSI_FMT_RGB888;
99 dsi->hs_rate = 349440000;
100 dsi->lp_rate = 9600000;
101 dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
102 MIPI_DSI_MODE_VIDEO_BURST;
104 ret = s6e63m0_probe(dev, NULL, s6e63m0_dsi_dcs_read,
105 s6e63m0_dsi_dcs_write, true);
109 ret = mipi_dsi_attach(dsi);
116 static int s6e63m0_dsi_remove(struct mipi_dsi_device *dsi)
118 mipi_dsi_detach(dsi);
119 s6e63m0_remove(&dsi->dev);
123 static const struct of_device_id s6e63m0_dsi_of_match[] = {
124 { .compatible = "samsung,s6e63m0" },
127 MODULE_DEVICE_TABLE(of, s6e63m0_dsi_of_match);
129 static struct mipi_dsi_driver s6e63m0_dsi_driver = {
130 .probe = s6e63m0_dsi_probe,
131 .remove = s6e63m0_dsi_remove,
133 .name = "panel-samsung-s6e63m0",
134 .of_match_table = s6e63m0_dsi_of_match,
137 module_mipi_dsi_driver(s6e63m0_dsi_driver);
139 MODULE_AUTHOR("Linus Walleij <linusw@kernel.org>");
140 MODULE_DESCRIPTION("s6e63m0 LCD DSI Driver");
141 MODULE_LICENSE("GPL v2");