1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2022 Joel Selvaraj <jo@jsfamily.in>
4 * Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree:
5 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
8 #include <linux/delay.h>
9 #include <linux/gpio/consumer.h>
10 #include <linux/regulator/consumer.h>
11 #include <linux/module.h>
14 #include <video/mipi_display.h>
16 #include <drm/drm_mipi_dsi.h>
17 #include <drm/drm_modes.h>
18 #include <drm/drm_panel.h>
20 static const char * const regulator_names[] = {
26 static const unsigned long regulator_enable_loads[] = {
33 struct drm_panel panel;
34 struct mipi_dsi_device *dsi;
36 struct regulator_bulk_data supplies[ARRAY_SIZE(regulator_names)];
38 struct gpio_desc *reset_gpio;
42 struct ebbg_ft8719 *to_ebbg_ft8719(struct drm_panel *panel)
44 return container_of(panel, struct ebbg_ft8719, panel);
47 static void ebbg_ft8719_reset(struct ebbg_ft8719 *ctx)
49 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
50 usleep_range(4000, 5000);
51 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
52 usleep_range(1000, 2000);
53 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
54 usleep_range(15000, 16000);
57 static int ebbg_ft8719_on(struct ebbg_ft8719 *ctx)
59 struct mipi_dsi_device *dsi = ctx->dsi;
60 struct device *dev = &dsi->dev;
63 dsi->mode_flags |= MIPI_DSI_MODE_LPM;
65 ret = mipi_dsi_dcs_set_display_brightness(dsi, 0x00ff);
67 dev_err(dev, "Failed to set display brightness: %d\n", ret);
71 mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, 0x24);
72 mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_POWER_SAVE, 0x00);
74 ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
76 dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
81 ret = mipi_dsi_dcs_set_display_on(dsi);
83 dev_err(dev, "Failed to set display on: %d\n", ret);
90 static int ebbg_ft8719_off(struct ebbg_ft8719 *ctx)
92 struct mipi_dsi_device *dsi = ctx->dsi;
93 struct device *dev = &dsi->dev;
96 dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
98 ret = mipi_dsi_dcs_set_display_off(dsi);
100 dev_err(dev, "Failed to set display off: %d\n", ret);
103 usleep_range(10000, 11000);
105 ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
107 dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
115 static int ebbg_ft8719_prepare(struct drm_panel *panel)
117 struct ebbg_ft8719 *ctx = to_ebbg_ft8719(panel);
118 struct device *dev = &ctx->dsi->dev;
121 ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
125 ebbg_ft8719_reset(ctx);
127 ret = ebbg_ft8719_on(ctx);
129 dev_err(dev, "Failed to initialize panel: %d\n", ret);
130 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
137 static int ebbg_ft8719_unprepare(struct drm_panel *panel)
139 struct ebbg_ft8719 *ctx = to_ebbg_ft8719(panel);
140 struct device *dev = &ctx->dsi->dev;
143 ret = ebbg_ft8719_off(ctx);
145 dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
147 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
149 ret = regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
151 dev_err(panel->dev, "Failed to disable regulators: %d\n", ret);
156 static const struct drm_display_mode ebbg_ft8719_mode = {
157 .clock = (1080 + 28 + 4 + 16) * (2246 + 120 + 4 + 12) * 60 / 1000,
159 .hsync_start = 1080 + 28,
160 .hsync_end = 1080 + 28 + 4,
161 .htotal = 1080 + 28 + 4 + 16,
163 .vsync_start = 2246 + 120,
164 .vsync_end = 2246 + 120 + 4,
165 .vtotal = 2246 + 120 + 4 + 12,
170 static int ebbg_ft8719_get_modes(struct drm_panel *panel,
171 struct drm_connector *connector)
173 struct drm_display_mode *mode;
175 mode = drm_mode_duplicate(connector->dev, &ebbg_ft8719_mode);
179 drm_mode_set_name(mode);
181 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
182 connector->display_info.width_mm = mode->width_mm;
183 connector->display_info.height_mm = mode->height_mm;
184 drm_mode_probed_add(connector, mode);
189 static const struct drm_panel_funcs ebbg_ft8719_panel_funcs = {
190 .prepare = ebbg_ft8719_prepare,
191 .unprepare = ebbg_ft8719_unprepare,
192 .get_modes = ebbg_ft8719_get_modes,
195 static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi)
197 struct device *dev = &dsi->dev;
198 struct ebbg_ft8719 *ctx;
201 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
205 for (i = 0; i < ARRAY_SIZE(ctx->supplies); i++)
206 ctx->supplies[i].supply = regulator_names[i];
208 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
211 return dev_err_probe(dev, ret, "Failed to get regulators\n");
213 for (i = 0; i < ARRAY_SIZE(ctx->supplies); i++) {
214 ret = regulator_set_load(ctx->supplies[i].consumer,
215 regulator_enable_loads[i]);
217 return dev_err_probe(dev, ret,
218 "Failed to set regulator load\n");
221 ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
222 if (IS_ERR(ctx->reset_gpio))
223 return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
224 "Failed to get reset-gpios\n");
227 mipi_dsi_set_drvdata(dsi, ctx);
230 dsi->format = MIPI_DSI_FMT_RGB888;
231 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
232 MIPI_DSI_CLOCK_NON_CONTINUOUS;
234 drm_panel_init(&ctx->panel, dev, &ebbg_ft8719_panel_funcs,
235 DRM_MODE_CONNECTOR_DSI);
237 ret = drm_panel_of_backlight(&ctx->panel);
239 return dev_err_probe(dev, ret, "Failed to get backlight\n");
241 drm_panel_add(&ctx->panel);
243 ret = mipi_dsi_attach(dsi);
245 dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
246 drm_panel_remove(&ctx->panel);
253 static void ebbg_ft8719_remove(struct mipi_dsi_device *dsi)
255 struct ebbg_ft8719 *ctx = mipi_dsi_get_drvdata(dsi);
258 ret = mipi_dsi_detach(dsi);
260 dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
262 drm_panel_remove(&ctx->panel);
265 static const struct of_device_id ebbg_ft8719_of_match[] = {
266 { .compatible = "ebbg,ft8719" },
269 MODULE_DEVICE_TABLE(of, ebbg_ft8719_of_match);
271 static struct mipi_dsi_driver ebbg_ft8719_driver = {
272 .probe = ebbg_ft8719_probe,
273 .remove = ebbg_ft8719_remove,
275 .name = "panel-ebbg-ft8719",
276 .of_match_table = ebbg_ft8719_of_match,
279 module_mipi_dsi_driver(ebbg_ft8719_driver);
281 MODULE_AUTHOR("Joel Selvaraj <jo@jsfamily.in>");
282 MODULE_DESCRIPTION("DRM driver for EBBG FT8719 video dsi panel");
283 MODULE_LICENSE("GPL v2");