1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2019, The Linux Foundation. All rights reserved.
6 #include <linux/delay.h>
7 #include <linux/module.h>
8 #include <linux/of_device.h>
9 #include <linux/gpio/consumer.h>
10 #include <linux/regulator/consumer.h>
12 #include <video/mipi_display.h>
14 #include <drm/drm_mipi_dsi.h>
15 #include <drm/drm_modes.h>
16 #include <drm/drm_panel.h>
18 struct visionox_rm69299 {
19 struct drm_panel panel;
20 struct regulator_bulk_data supplies[2];
21 struct gpio_desc *reset_gpio;
22 struct mipi_dsi_device *dsi;
27 static inline struct visionox_rm69299 *panel_to_ctx(struct drm_panel *panel)
29 return container_of(panel, struct visionox_rm69299, panel);
32 static int visionox_rm69299_power_on(struct visionox_rm69299 *ctx)
36 ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
41 * Reset sequence of visionox panel requires the panel to be
42 * out of reset for 10ms, followed by being held in reset
43 * for 10ms and then out again
45 gpiod_set_value(ctx->reset_gpio, 1);
46 usleep_range(10000, 20000);
47 gpiod_set_value(ctx->reset_gpio, 0);
48 usleep_range(10000, 20000);
49 gpiod_set_value(ctx->reset_gpio, 1);
50 usleep_range(10000, 20000);
55 static int visionox_rm69299_power_off(struct visionox_rm69299 *ctx)
57 gpiod_set_value(ctx->reset_gpio, 0);
59 return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
62 static int visionox_rm69299_unprepare(struct drm_panel *panel)
64 struct visionox_rm69299 *ctx = panel_to_ctx(panel);
67 ctx->dsi->mode_flags = 0;
69 ret = mipi_dsi_dcs_write(ctx->dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
71 dev_err(ctx->panel.dev, "set_display_off cmd failed ret = %d\n", ret);
73 /* 120ms delay required here as per DCS spec */
76 ret = mipi_dsi_dcs_write(ctx->dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
78 dev_err(ctx->panel.dev, "enter_sleep cmd failed ret = %d\n", ret);
81 ret = visionox_rm69299_power_off(ctx);
83 ctx->prepared = false;
87 static int visionox_rm69299_prepare(struct drm_panel *panel)
89 struct visionox_rm69299 *ctx = panel_to_ctx(panel);
95 ret = visionox_rm69299_power_on(ctx);
99 ctx->dsi->mode_flags |= MIPI_DSI_MODE_LPM;
101 ret = mipi_dsi_dcs_write_buffer(ctx->dsi, (u8[]) { 0xfe, 0x00 }, 2);
103 dev_err(ctx->panel.dev, "cmd set tx 0 failed, ret = %d\n", ret);
107 ret = mipi_dsi_dcs_write_buffer(ctx->dsi, (u8[]) { 0xc2, 0x08 }, 2);
109 dev_err(ctx->panel.dev, "cmd set tx 1 failed, ret = %d\n", ret);
113 ret = mipi_dsi_dcs_write_buffer(ctx->dsi, (u8[]) { 0x35, 0x00 }, 2);
115 dev_err(ctx->panel.dev, "cmd set tx 2 failed, ret = %d\n", ret);
119 ret = mipi_dsi_dcs_write_buffer(ctx->dsi, (u8[]) { 0x51, 0xff }, 2);
121 dev_err(ctx->panel.dev, "cmd set tx 3 failed, ret = %d\n", ret);
125 ret = mipi_dsi_dcs_write(ctx->dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
127 dev_err(ctx->panel.dev, "exit_sleep_mode cmd failed ret = %d\n", ret);
131 /* Per DSI spec wait 120ms after sending exit sleep DCS command */
134 ret = mipi_dsi_dcs_write(ctx->dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
136 dev_err(ctx->panel.dev, "set_display_on cmd failed ret = %d\n", ret);
140 /* Per DSI spec wait 120ms after sending set_display_on DCS command */
143 ctx->prepared = true;
151 static const struct drm_display_mode visionox_rm69299_1080x2248_60hz = {
155 .hsync_start = 1080 + 26,
156 .hsync_end = 1080 + 26 + 2,
157 .htotal = 1080 + 26 + 2 + 36,
159 .vsync_start = 2248 + 56,
160 .vsync_end = 2248 + 56 + 4,
161 .vtotal = 2248 + 56 + 4 + 4,
165 static int visionox_rm69299_get_modes(struct drm_panel *panel,
166 struct drm_connector *connector)
168 struct visionox_rm69299 *ctx = panel_to_ctx(panel);
169 struct drm_display_mode *mode;
171 mode = drm_mode_create(connector->dev);
173 dev_err(ctx->panel.dev, "failed to create a new display mode\n");
177 connector->display_info.width_mm = 74;
178 connector->display_info.height_mm = 131;
179 drm_mode_copy(mode, &visionox_rm69299_1080x2248_60hz);
180 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
181 drm_mode_probed_add(connector, mode);
186 static const struct drm_panel_funcs visionox_rm69299_drm_funcs = {
187 .unprepare = visionox_rm69299_unprepare,
188 .prepare = visionox_rm69299_prepare,
189 .get_modes = visionox_rm69299_get_modes,
192 static int visionox_rm69299_probe(struct mipi_dsi_device *dsi)
194 struct device *dev = &dsi->dev;
195 struct visionox_rm69299 *ctx;
198 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
202 mipi_dsi_set_drvdata(dsi, ctx);
204 ctx->panel.dev = dev;
207 ctx->supplies[0].supply = "vdda";
208 ctx->supplies[1].supply = "vdd3p3";
210 ret = devm_regulator_bulk_get(ctx->panel.dev, ARRAY_SIZE(ctx->supplies),
215 ctx->reset_gpio = devm_gpiod_get(ctx->panel.dev,
216 "reset", GPIOD_OUT_LOW);
217 if (IS_ERR(ctx->reset_gpio)) {
218 dev_err(dev, "cannot get reset gpio %ld\n", PTR_ERR(ctx->reset_gpio));
219 return PTR_ERR(ctx->reset_gpio);
222 drm_panel_init(&ctx->panel, dev, &visionox_rm69299_drm_funcs,
223 DRM_MODE_CONNECTOR_DSI);
224 ctx->panel.dev = dev;
225 ctx->panel.funcs = &visionox_rm69299_drm_funcs;
226 drm_panel_add(&ctx->panel);
229 dsi->format = MIPI_DSI_FMT_RGB888;
230 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_LPM |
231 MIPI_DSI_CLOCK_NON_CONTINUOUS;
232 ret = mipi_dsi_attach(dsi);
234 dev_err(dev, "dsi attach failed ret = %d\n", ret);
238 ret = regulator_set_load(ctx->supplies[0].consumer, 32000);
240 dev_err(dev, "regulator set load failed for vdda supply ret = %d\n", ret);
244 ret = regulator_set_load(ctx->supplies[1].consumer, 13200);
246 dev_err(dev, "regulator set load failed for vdd3p3 supply ret = %d\n", ret);
253 mipi_dsi_detach(dsi);
255 drm_panel_remove(&ctx->panel);
259 static int visionox_rm69299_remove(struct mipi_dsi_device *dsi)
261 struct visionox_rm69299 *ctx = mipi_dsi_get_drvdata(dsi);
263 mipi_dsi_detach(ctx->dsi);
264 mipi_dsi_device_unregister(ctx->dsi);
266 drm_panel_remove(&ctx->panel);
270 static const struct of_device_id visionox_rm69299_of_match[] = {
271 { .compatible = "visionox,rm69299-1080p-display", },
274 MODULE_DEVICE_TABLE(of, visionox_rm69299_of_match);
276 static struct mipi_dsi_driver visionox_rm69299_driver = {
278 .name = "panel-visionox-rm69299",
279 .of_match_table = visionox_rm69299_of_match,
281 .probe = visionox_rm69299_probe,
282 .remove = visionox_rm69299_remove,
284 module_mipi_dsi_driver(visionox_rm69299_driver);
286 MODULE_DESCRIPTION("Visionox RM69299 DSI Panel Driver");
287 MODULE_LICENSE("GPL v2");