1b00de0e2SJoel Selvaraj // SPDX-License-Identifier: GPL-2.0-only
2b00de0e2SJoel Selvaraj /*
3b00de0e2SJoel Selvaraj * Copyright (c) 2022 Joel Selvaraj <jo@jsfamily.in>
4b00de0e2SJoel Selvaraj * Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree:
5b00de0e2SJoel Selvaraj * Copyright (c) 2013, The Linux Foundation. All rights reserved.
6b00de0e2SJoel Selvaraj */
7b00de0e2SJoel Selvaraj
8b00de0e2SJoel Selvaraj #include <linux/delay.h>
9b00de0e2SJoel Selvaraj #include <linux/gpio/consumer.h>
10b00de0e2SJoel Selvaraj #include <linux/regulator/consumer.h>
11b00de0e2SJoel Selvaraj #include <linux/module.h>
12b00de0e2SJoel Selvaraj #include <linux/of.h>
13b00de0e2SJoel Selvaraj
14b00de0e2SJoel Selvaraj #include <video/mipi_display.h>
15b00de0e2SJoel Selvaraj
16b00de0e2SJoel Selvaraj #include <drm/drm_mipi_dsi.h>
17b00de0e2SJoel Selvaraj #include <drm/drm_modes.h>
18b00de0e2SJoel Selvaraj #include <drm/drm_panel.h>
19b00de0e2SJoel Selvaraj
20b00de0e2SJoel Selvaraj static const char * const regulator_names[] = {
21b00de0e2SJoel Selvaraj "vddio",
22b00de0e2SJoel Selvaraj "vddpos",
23b00de0e2SJoel Selvaraj "vddneg",
24b00de0e2SJoel Selvaraj };
25b00de0e2SJoel Selvaraj
26b00de0e2SJoel Selvaraj static const unsigned long regulator_enable_loads[] = {
27b00de0e2SJoel Selvaraj 62000,
28b00de0e2SJoel Selvaraj 100000,
29b00de0e2SJoel Selvaraj 100000
30b00de0e2SJoel Selvaraj };
31b00de0e2SJoel Selvaraj
32b00de0e2SJoel Selvaraj struct ebbg_ft8719 {
33b00de0e2SJoel Selvaraj struct drm_panel panel;
34b00de0e2SJoel Selvaraj struct mipi_dsi_device *dsi;
35b00de0e2SJoel Selvaraj
36b00de0e2SJoel Selvaraj struct regulator_bulk_data supplies[ARRAY_SIZE(regulator_names)];
37b00de0e2SJoel Selvaraj
38b00de0e2SJoel Selvaraj struct gpio_desc *reset_gpio;
39b00de0e2SJoel Selvaraj };
40b00de0e2SJoel Selvaraj
41b00de0e2SJoel Selvaraj static inline
to_ebbg_ft8719(struct drm_panel * panel)42b00de0e2SJoel Selvaraj struct ebbg_ft8719 *to_ebbg_ft8719(struct drm_panel *panel)
43b00de0e2SJoel Selvaraj {
44b00de0e2SJoel Selvaraj return container_of(panel, struct ebbg_ft8719, panel);
45b00de0e2SJoel Selvaraj }
46b00de0e2SJoel Selvaraj
ebbg_ft8719_reset(struct ebbg_ft8719 * ctx)47b00de0e2SJoel Selvaraj static void ebbg_ft8719_reset(struct ebbg_ft8719 *ctx)
48b00de0e2SJoel Selvaraj {
49b00de0e2SJoel Selvaraj gpiod_set_value_cansleep(ctx->reset_gpio, 0);
50b00de0e2SJoel Selvaraj usleep_range(4000, 5000);
51b00de0e2SJoel Selvaraj gpiod_set_value_cansleep(ctx->reset_gpio, 1);
52b00de0e2SJoel Selvaraj usleep_range(1000, 2000);
53b00de0e2SJoel Selvaraj gpiod_set_value_cansleep(ctx->reset_gpio, 0);
54b00de0e2SJoel Selvaraj usleep_range(15000, 16000);
55b00de0e2SJoel Selvaraj }
56b00de0e2SJoel Selvaraj
ebbg_ft8719_on(struct ebbg_ft8719 * ctx)57b00de0e2SJoel Selvaraj static int ebbg_ft8719_on(struct ebbg_ft8719 *ctx)
58b00de0e2SJoel Selvaraj {
59b00de0e2SJoel Selvaraj struct mipi_dsi_device *dsi = ctx->dsi;
60b00de0e2SJoel Selvaraj struct device *dev = &dsi->dev;
61b00de0e2SJoel Selvaraj int ret;
62b00de0e2SJoel Selvaraj
63b00de0e2SJoel Selvaraj dsi->mode_flags |= MIPI_DSI_MODE_LPM;
64b00de0e2SJoel Selvaraj
65b00de0e2SJoel Selvaraj ret = mipi_dsi_dcs_set_display_brightness(dsi, 0x00ff);
66b00de0e2SJoel Selvaraj if (ret < 0) {
67b00de0e2SJoel Selvaraj dev_err(dev, "Failed to set display brightness: %d\n", ret);
68b00de0e2SJoel Selvaraj return ret;
69b00de0e2SJoel Selvaraj }
70b00de0e2SJoel Selvaraj
71b00de0e2SJoel Selvaraj mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, 0x24);
72b00de0e2SJoel Selvaraj mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_POWER_SAVE, 0x00);
73b00de0e2SJoel Selvaraj
74b00de0e2SJoel Selvaraj ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
75b00de0e2SJoel Selvaraj if (ret < 0) {
76b00de0e2SJoel Selvaraj dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
77b00de0e2SJoel Selvaraj return ret;
78b00de0e2SJoel Selvaraj }
79b00de0e2SJoel Selvaraj msleep(90);
80b00de0e2SJoel Selvaraj
81b00de0e2SJoel Selvaraj ret = mipi_dsi_dcs_set_display_on(dsi);
82b00de0e2SJoel Selvaraj if (ret < 0) {
83b00de0e2SJoel Selvaraj dev_err(dev, "Failed to set display on: %d\n", ret);
84b00de0e2SJoel Selvaraj return ret;
85b00de0e2SJoel Selvaraj }
86b00de0e2SJoel Selvaraj
87b00de0e2SJoel Selvaraj return 0;
88b00de0e2SJoel Selvaraj }
89b00de0e2SJoel Selvaraj
ebbg_ft8719_off(struct ebbg_ft8719 * ctx)90b00de0e2SJoel Selvaraj static int ebbg_ft8719_off(struct ebbg_ft8719 *ctx)
91b00de0e2SJoel Selvaraj {
92b00de0e2SJoel Selvaraj struct mipi_dsi_device *dsi = ctx->dsi;
93b00de0e2SJoel Selvaraj struct device *dev = &dsi->dev;
94b00de0e2SJoel Selvaraj int ret;
95b00de0e2SJoel Selvaraj
96b00de0e2SJoel Selvaraj dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
97b00de0e2SJoel Selvaraj
98b00de0e2SJoel Selvaraj ret = mipi_dsi_dcs_set_display_off(dsi);
99b00de0e2SJoel Selvaraj if (ret < 0) {
100b00de0e2SJoel Selvaraj dev_err(dev, "Failed to set display off: %d\n", ret);
101b00de0e2SJoel Selvaraj return ret;
102b00de0e2SJoel Selvaraj }
103b00de0e2SJoel Selvaraj usleep_range(10000, 11000);
104b00de0e2SJoel Selvaraj
105b00de0e2SJoel Selvaraj ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
106b00de0e2SJoel Selvaraj if (ret < 0) {
107b00de0e2SJoel Selvaraj dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
108b00de0e2SJoel Selvaraj return ret;
109b00de0e2SJoel Selvaraj }
110b00de0e2SJoel Selvaraj msleep(90);
111b00de0e2SJoel Selvaraj
112b00de0e2SJoel Selvaraj return 0;
113b00de0e2SJoel Selvaraj }
114b00de0e2SJoel Selvaraj
ebbg_ft8719_prepare(struct drm_panel * panel)115b00de0e2SJoel Selvaraj static int ebbg_ft8719_prepare(struct drm_panel *panel)
116b00de0e2SJoel Selvaraj {
117b00de0e2SJoel Selvaraj struct ebbg_ft8719 *ctx = to_ebbg_ft8719(panel);
118b00de0e2SJoel Selvaraj struct device *dev = &ctx->dsi->dev;
119b00de0e2SJoel Selvaraj int ret;
120b00de0e2SJoel Selvaraj
121b00de0e2SJoel Selvaraj ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
122b00de0e2SJoel Selvaraj if (ret < 0)
123b00de0e2SJoel Selvaraj return ret;
124b00de0e2SJoel Selvaraj
125b00de0e2SJoel Selvaraj ebbg_ft8719_reset(ctx);
126b00de0e2SJoel Selvaraj
127b00de0e2SJoel Selvaraj ret = ebbg_ft8719_on(ctx);
128b00de0e2SJoel Selvaraj if (ret < 0) {
129b00de0e2SJoel Selvaraj dev_err(dev, "Failed to initialize panel: %d\n", ret);
130b00de0e2SJoel Selvaraj gpiod_set_value_cansleep(ctx->reset_gpio, 1);
131b00de0e2SJoel Selvaraj return ret;
132b00de0e2SJoel Selvaraj }
133b00de0e2SJoel Selvaraj
134b00de0e2SJoel Selvaraj return 0;
135b00de0e2SJoel Selvaraj }
136b00de0e2SJoel Selvaraj
ebbg_ft8719_unprepare(struct drm_panel * panel)137b00de0e2SJoel Selvaraj static int ebbg_ft8719_unprepare(struct drm_panel *panel)
138b00de0e2SJoel Selvaraj {
139b00de0e2SJoel Selvaraj struct ebbg_ft8719 *ctx = to_ebbg_ft8719(panel);
140b00de0e2SJoel Selvaraj struct device *dev = &ctx->dsi->dev;
141b00de0e2SJoel Selvaraj int ret;
142b00de0e2SJoel Selvaraj
143b00de0e2SJoel Selvaraj ret = ebbg_ft8719_off(ctx);
144b00de0e2SJoel Selvaraj if (ret < 0)
145b00de0e2SJoel Selvaraj dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
146b00de0e2SJoel Selvaraj
147b00de0e2SJoel Selvaraj gpiod_set_value_cansleep(ctx->reset_gpio, 1);
148b00de0e2SJoel Selvaraj
149b00de0e2SJoel Selvaraj ret = regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
150b00de0e2SJoel Selvaraj if (ret)
151b00de0e2SJoel Selvaraj dev_err(panel->dev, "Failed to disable regulators: %d\n", ret);
152b00de0e2SJoel Selvaraj
153b00de0e2SJoel Selvaraj return 0;
154b00de0e2SJoel Selvaraj }
155b00de0e2SJoel Selvaraj
156b00de0e2SJoel Selvaraj static const struct drm_display_mode ebbg_ft8719_mode = {
157b00de0e2SJoel Selvaraj .clock = (1080 + 28 + 4 + 16) * (2246 + 120 + 4 + 12) * 60 / 1000,
158b00de0e2SJoel Selvaraj .hdisplay = 1080,
159b00de0e2SJoel Selvaraj .hsync_start = 1080 + 28,
160b00de0e2SJoel Selvaraj .hsync_end = 1080 + 28 + 4,
161b00de0e2SJoel Selvaraj .htotal = 1080 + 28 + 4 + 16,
162b00de0e2SJoel Selvaraj .vdisplay = 2246,
163b00de0e2SJoel Selvaraj .vsync_start = 2246 + 120,
164b00de0e2SJoel Selvaraj .vsync_end = 2246 + 120 + 4,
165b00de0e2SJoel Selvaraj .vtotal = 2246 + 120 + 4 + 12,
166b00de0e2SJoel Selvaraj .width_mm = 68,
167b00de0e2SJoel Selvaraj .height_mm = 141,
168b00de0e2SJoel Selvaraj };
169b00de0e2SJoel Selvaraj
ebbg_ft8719_get_modes(struct drm_panel * panel,struct drm_connector * connector)170b00de0e2SJoel Selvaraj static int ebbg_ft8719_get_modes(struct drm_panel *panel,
171b00de0e2SJoel Selvaraj struct drm_connector *connector)
172b00de0e2SJoel Selvaraj {
173b00de0e2SJoel Selvaraj struct drm_display_mode *mode;
174b00de0e2SJoel Selvaraj
175b00de0e2SJoel Selvaraj mode = drm_mode_duplicate(connector->dev, &ebbg_ft8719_mode);
176b00de0e2SJoel Selvaraj if (!mode)
177b00de0e2SJoel Selvaraj return -ENOMEM;
178b00de0e2SJoel Selvaraj
179b00de0e2SJoel Selvaraj drm_mode_set_name(mode);
180b00de0e2SJoel Selvaraj
181b00de0e2SJoel Selvaraj mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
182b00de0e2SJoel Selvaraj connector->display_info.width_mm = mode->width_mm;
183b00de0e2SJoel Selvaraj connector->display_info.height_mm = mode->height_mm;
184b00de0e2SJoel Selvaraj drm_mode_probed_add(connector, mode);
185b00de0e2SJoel Selvaraj
186b00de0e2SJoel Selvaraj return 1;
187b00de0e2SJoel Selvaraj }
188b00de0e2SJoel Selvaraj
189b00de0e2SJoel Selvaraj static const struct drm_panel_funcs ebbg_ft8719_panel_funcs = {
190b00de0e2SJoel Selvaraj .prepare = ebbg_ft8719_prepare,
191b00de0e2SJoel Selvaraj .unprepare = ebbg_ft8719_unprepare,
192b00de0e2SJoel Selvaraj .get_modes = ebbg_ft8719_get_modes,
193b00de0e2SJoel Selvaraj };
194b00de0e2SJoel Selvaraj
ebbg_ft8719_probe(struct mipi_dsi_device * dsi)195b00de0e2SJoel Selvaraj static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi)
196b00de0e2SJoel Selvaraj {
197b00de0e2SJoel Selvaraj struct device *dev = &dsi->dev;
198b00de0e2SJoel Selvaraj struct ebbg_ft8719 *ctx;
199b00de0e2SJoel Selvaraj int i, ret;
200b00de0e2SJoel Selvaraj
201b00de0e2SJoel Selvaraj ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
202b00de0e2SJoel Selvaraj if (!ctx)
203b00de0e2SJoel Selvaraj return -ENOMEM;
204b00de0e2SJoel Selvaraj
205b00de0e2SJoel Selvaraj for (i = 0; i < ARRAY_SIZE(ctx->supplies); i++)
206b00de0e2SJoel Selvaraj ctx->supplies[i].supply = regulator_names[i];
207b00de0e2SJoel Selvaraj
208b00de0e2SJoel Selvaraj ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
209b00de0e2SJoel Selvaraj ctx->supplies);
210b00de0e2SJoel Selvaraj if (ret < 0)
211b00de0e2SJoel Selvaraj return dev_err_probe(dev, ret, "Failed to get regulators\n");
212b00de0e2SJoel Selvaraj
213b00de0e2SJoel Selvaraj for (i = 0; i < ARRAY_SIZE(ctx->supplies); i++) {
214b00de0e2SJoel Selvaraj ret = regulator_set_load(ctx->supplies[i].consumer,
215b00de0e2SJoel Selvaraj regulator_enable_loads[i]);
216b00de0e2SJoel Selvaraj if (ret)
217b00de0e2SJoel Selvaraj return dev_err_probe(dev, ret,
218b00de0e2SJoel Selvaraj "Failed to set regulator load\n");
219b00de0e2SJoel Selvaraj }
220b00de0e2SJoel Selvaraj
221b00de0e2SJoel Selvaraj ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
222b00de0e2SJoel Selvaraj if (IS_ERR(ctx->reset_gpio))
223b00de0e2SJoel Selvaraj return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
224b00de0e2SJoel Selvaraj "Failed to get reset-gpios\n");
225b00de0e2SJoel Selvaraj
226b00de0e2SJoel Selvaraj ctx->dsi = dsi;
227b00de0e2SJoel Selvaraj mipi_dsi_set_drvdata(dsi, ctx);
228b00de0e2SJoel Selvaraj
229b00de0e2SJoel Selvaraj dsi->lanes = 4;
230b00de0e2SJoel Selvaraj dsi->format = MIPI_DSI_FMT_RGB888;
231b00de0e2SJoel Selvaraj dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
232b00de0e2SJoel Selvaraj MIPI_DSI_CLOCK_NON_CONTINUOUS;
233b00de0e2SJoel Selvaraj
234b00de0e2SJoel Selvaraj drm_panel_init(&ctx->panel, dev, &ebbg_ft8719_panel_funcs,
235b00de0e2SJoel Selvaraj DRM_MODE_CONNECTOR_DSI);
236b00de0e2SJoel Selvaraj
237b00de0e2SJoel Selvaraj ret = drm_panel_of_backlight(&ctx->panel);
238b00de0e2SJoel Selvaraj if (ret)
239b00de0e2SJoel Selvaraj return dev_err_probe(dev, ret, "Failed to get backlight\n");
240b00de0e2SJoel Selvaraj
241b00de0e2SJoel Selvaraj drm_panel_add(&ctx->panel);
242b00de0e2SJoel Selvaraj
243b00de0e2SJoel Selvaraj ret = mipi_dsi_attach(dsi);
244b00de0e2SJoel Selvaraj if (ret < 0) {
245b00de0e2SJoel Selvaraj dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
246b00de0e2SJoel Selvaraj drm_panel_remove(&ctx->panel);
247b00de0e2SJoel Selvaraj return ret;
248b00de0e2SJoel Selvaraj }
249b00de0e2SJoel Selvaraj
250b00de0e2SJoel Selvaraj return 0;
251b00de0e2SJoel Selvaraj }
252b00de0e2SJoel Selvaraj
ebbg_ft8719_remove(struct mipi_dsi_device * dsi)253*79abca2bSUwe Kleine-König static void ebbg_ft8719_remove(struct mipi_dsi_device *dsi)
254b00de0e2SJoel Selvaraj {
255b00de0e2SJoel Selvaraj struct ebbg_ft8719 *ctx = mipi_dsi_get_drvdata(dsi);
256b00de0e2SJoel Selvaraj int ret;
257b00de0e2SJoel Selvaraj
258b00de0e2SJoel Selvaraj ret = mipi_dsi_detach(dsi);
259b00de0e2SJoel Selvaraj if (ret < 0)
260b00de0e2SJoel Selvaraj dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
261b00de0e2SJoel Selvaraj
262b00de0e2SJoel Selvaraj drm_panel_remove(&ctx->panel);
263b00de0e2SJoel Selvaraj }
264b00de0e2SJoel Selvaraj
265b00de0e2SJoel Selvaraj static const struct of_device_id ebbg_ft8719_of_match[] = {
266b00de0e2SJoel Selvaraj { .compatible = "ebbg,ft8719" },
267b00de0e2SJoel Selvaraj { /* sentinel */ }
268b00de0e2SJoel Selvaraj };
269b00de0e2SJoel Selvaraj MODULE_DEVICE_TABLE(of, ebbg_ft8719_of_match);
270b00de0e2SJoel Selvaraj
271b00de0e2SJoel Selvaraj static struct mipi_dsi_driver ebbg_ft8719_driver = {
272b00de0e2SJoel Selvaraj .probe = ebbg_ft8719_probe,
273b00de0e2SJoel Selvaraj .remove = ebbg_ft8719_remove,
274b00de0e2SJoel Selvaraj .driver = {
275b00de0e2SJoel Selvaraj .name = "panel-ebbg-ft8719",
276b00de0e2SJoel Selvaraj .of_match_table = ebbg_ft8719_of_match,
277b00de0e2SJoel Selvaraj },
278b00de0e2SJoel Selvaraj };
279b00de0e2SJoel Selvaraj module_mipi_dsi_driver(ebbg_ft8719_driver);
280b00de0e2SJoel Selvaraj
281b00de0e2SJoel Selvaraj MODULE_AUTHOR("Joel Selvaraj <jo@jsfamily.in>");
282b00de0e2SJoel Selvaraj MODULE_DESCRIPTION("DRM driver for EBBG FT8719 video dsi panel");
283b00de0e2SJoel Selvaraj MODULE_LICENSE("GPL v2");
284