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