1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018-2019, Bridge Systems BV
4 * Copyright (C) 2018-2019, Bootlin
5 * Copyright (C) 2017, Free Electrons
7 * This file based on panel-ilitek-ili9881c.c
10 #include <linux/delay.h>
11 #include <linux/device.h>
12 #include <linux/err.h>
13 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/media-bus-format.h>
17 #include <linux/module.h>
19 #include <linux/gpio/consumer.h>
20 #include <linux/regulator/consumer.h>
22 #include <drm/drm_connector.h>
23 #include <drm/drm_mipi_dsi.h>
24 #include <drm/drm_modes.h>
25 #include <drm/drm_panel.h>
27 struct rb070d30_panel {
28 struct drm_panel panel;
29 struct mipi_dsi_device *dsi;
30 struct regulator *supply;
33 struct gpio_desc *power;
34 struct gpio_desc *reset;
35 struct gpio_desc *updn;
36 struct gpio_desc *shlr;
40 static inline struct rb070d30_panel *panel_to_rb070d30_panel(struct drm_panel *panel)
42 return container_of(panel, struct rb070d30_panel, panel);
45 static int rb070d30_panel_prepare(struct drm_panel *panel)
47 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
50 ret = regulator_enable(ctx->supply);
52 dev_err(&ctx->dsi->dev, "Failed to enable supply: %d\n", ret);
57 gpiod_set_value(ctx->gpios.power, 1);
59 gpiod_set_value(ctx->gpios.reset, 1);
64 static int rb070d30_panel_unprepare(struct drm_panel *panel)
66 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
68 gpiod_set_value(ctx->gpios.reset, 0);
69 gpiod_set_value(ctx->gpios.power, 0);
70 regulator_disable(ctx->supply);
75 static int rb070d30_panel_enable(struct drm_panel *panel)
77 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
80 ret = mipi_dsi_dcs_exit_sleep_mode(ctx->dsi);
87 static int rb070d30_panel_disable(struct drm_panel *panel)
89 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
91 return mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
95 static const struct drm_display_mode default_mode = {
98 .hsync_start = 1024 + 160,
99 .hsync_end = 1024 + 160 + 80,
100 .htotal = 1024 + 160 + 80 + 80,
102 .vsync_start = 600 + 12,
103 .vsync_end = 600 + 12 + 10,
104 .vtotal = 600 + 12 + 10 + 13,
110 static int rb070d30_panel_get_modes(struct drm_panel *panel,
111 struct drm_connector *connector)
113 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
114 struct drm_display_mode *mode;
115 static const u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
117 mode = drm_mode_duplicate(connector->dev, &default_mode);
119 dev_err(&ctx->dsi->dev, "Failed to add mode " DRM_MODE_FMT "\n",
120 DRM_MODE_ARG(&default_mode));
124 drm_mode_set_name(mode);
126 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
127 drm_mode_probed_add(connector, mode);
129 connector->display_info.bpc = 8;
130 connector->display_info.width_mm = mode->width_mm;
131 connector->display_info.height_mm = mode->height_mm;
132 drm_display_info_set_bus_formats(&connector->display_info,
138 static const struct drm_panel_funcs rb070d30_panel_funcs = {
139 .get_modes = rb070d30_panel_get_modes,
140 .prepare = rb070d30_panel_prepare,
141 .enable = rb070d30_panel_enable,
142 .disable = rb070d30_panel_disable,
143 .unprepare = rb070d30_panel_unprepare,
146 static int rb070d30_panel_dsi_probe(struct mipi_dsi_device *dsi)
148 struct rb070d30_panel *ctx;
151 ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
155 ctx->supply = devm_regulator_get(&dsi->dev, "vcc-lcd");
156 if (IS_ERR(ctx->supply))
157 return PTR_ERR(ctx->supply);
159 mipi_dsi_set_drvdata(dsi, ctx);
162 drm_panel_init(&ctx->panel, &dsi->dev, &rb070d30_panel_funcs,
163 DRM_MODE_CONNECTOR_DSI);
165 ctx->gpios.reset = devm_gpiod_get(&dsi->dev, "reset", GPIOD_OUT_LOW);
166 if (IS_ERR(ctx->gpios.reset)) {
167 dev_err(&dsi->dev, "Couldn't get our reset GPIO\n");
168 return PTR_ERR(ctx->gpios.reset);
171 ctx->gpios.power = devm_gpiod_get(&dsi->dev, "power", GPIOD_OUT_LOW);
172 if (IS_ERR(ctx->gpios.power)) {
173 dev_err(&dsi->dev, "Couldn't get our power GPIO\n");
174 return PTR_ERR(ctx->gpios.power);
178 * We don't change the state of that GPIO later on but we need
179 * to force it into a low state.
181 ctx->gpios.updn = devm_gpiod_get(&dsi->dev, "updn", GPIOD_OUT_LOW);
182 if (IS_ERR(ctx->gpios.updn)) {
183 dev_err(&dsi->dev, "Couldn't get our updn GPIO\n");
184 return PTR_ERR(ctx->gpios.updn);
188 * We don't change the state of that GPIO later on but we need
189 * to force it into a low state.
191 ctx->gpios.shlr = devm_gpiod_get(&dsi->dev, "shlr", GPIOD_OUT_LOW);
192 if (IS_ERR(ctx->gpios.shlr)) {
193 dev_err(&dsi->dev, "Couldn't get our shlr GPIO\n");
194 return PTR_ERR(ctx->gpios.shlr);
197 ret = drm_panel_of_backlight(&ctx->panel);
201 drm_panel_add(&ctx->panel);
203 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | MIPI_DSI_MODE_LPM;
204 dsi->format = MIPI_DSI_FMT_RGB888;
207 return mipi_dsi_attach(dsi);
210 static int rb070d30_panel_dsi_remove(struct mipi_dsi_device *dsi)
212 struct rb070d30_panel *ctx = mipi_dsi_get_drvdata(dsi);
214 mipi_dsi_detach(dsi);
215 drm_panel_remove(&ctx->panel);
220 static const struct of_device_id rb070d30_panel_of_match[] = {
221 { .compatible = "ronbo,rb070d30" },
224 MODULE_DEVICE_TABLE(of, rb070d30_panel_of_match);
226 static struct mipi_dsi_driver rb070d30_panel_driver = {
227 .probe = rb070d30_panel_dsi_probe,
228 .remove = rb070d30_panel_dsi_remove,
230 .name = "panel-ronbo-rb070d30",
231 .of_match_table = rb070d30_panel_of_match,
234 module_mipi_dsi_driver(rb070d30_panel_driver);
236 MODULE_AUTHOR("Boris Brezillon <boris.brezillon@bootlin.com>");
237 MODULE_AUTHOR("Konstantin Sudakov <k.sudakov@integrasources.com>");
238 MODULE_DESCRIPTION("Ronbo RB070D30 Panel Driver");
239 MODULE_LICENSE("GPL");