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/backlight.h>
11 #include <linux/delay.h>
12 #include <linux/device.h>
13 #include <linux/err.h>
14 #include <linux/errno.h>
16 #include <linux/kernel.h>
17 #include <linux/media-bus-format.h>
18 #include <linux/module.h>
20 #include <linux/gpio/consumer.h>
21 #include <linux/regulator/consumer.h>
23 #include <drm/drm_connector.h>
24 #include <drm/drm_mipi_dsi.h>
25 #include <drm/drm_modes.h>
26 #include <drm/drm_panel.h>
27 #include <drm/drm_print.h>
29 struct rb070d30_panel {
30 struct drm_panel panel;
31 struct mipi_dsi_device *dsi;
32 struct backlight_device *backlight;
33 struct regulator *supply;
36 struct gpio_desc *power;
37 struct gpio_desc *reset;
38 struct gpio_desc *updn;
39 struct gpio_desc *shlr;
43 static inline struct rb070d30_panel *panel_to_rb070d30_panel(struct drm_panel *panel)
45 return container_of(panel, struct rb070d30_panel, panel);
48 static int rb070d30_panel_prepare(struct drm_panel *panel)
50 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
53 ret = regulator_enable(ctx->supply);
55 DRM_DEV_ERROR(&ctx->dsi->dev, "Failed to enable supply: %d\n", ret);
60 gpiod_set_value(ctx->gpios.power, 1);
62 gpiod_set_value(ctx->gpios.reset, 1);
67 static int rb070d30_panel_unprepare(struct drm_panel *panel)
69 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
71 gpiod_set_value(ctx->gpios.reset, 0);
72 gpiod_set_value(ctx->gpios.power, 0);
73 regulator_disable(ctx->supply);
78 static int rb070d30_panel_enable(struct drm_panel *panel)
80 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
83 ret = mipi_dsi_dcs_exit_sleep_mode(ctx->dsi);
87 ret = backlight_enable(ctx->backlight);
94 mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
98 static int rb070d30_panel_disable(struct drm_panel *panel)
100 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
102 backlight_disable(ctx->backlight);
103 return mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
106 /* Default timings */
107 static const struct drm_display_mode default_mode = {
110 .hsync_start = 1024 + 160,
111 .hsync_end = 1024 + 160 + 80,
112 .htotal = 1024 + 160 + 80 + 80,
114 .vsync_start = 600 + 12,
115 .vsync_end = 600 + 12 + 10,
116 .vtotal = 600 + 12 + 10 + 13,
123 static int rb070d30_panel_get_modes(struct drm_panel *panel)
125 struct drm_connector *connector = panel->connector;
126 struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
127 struct drm_display_mode *mode;
128 static const u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
130 mode = drm_mode_duplicate(panel->drm, &default_mode);
132 DRM_DEV_ERROR(&ctx->dsi->dev,
133 "Failed to add mode " DRM_MODE_FMT "\n",
134 DRM_MODE_ARG(&default_mode));
138 drm_mode_set_name(mode);
140 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
141 drm_mode_probed_add(connector, mode);
143 panel->connector->display_info.bpc = 8;
144 panel->connector->display_info.width_mm = mode->width_mm;
145 panel->connector->display_info.height_mm = mode->height_mm;
146 drm_display_info_set_bus_formats(&connector->display_info,
152 static const struct drm_panel_funcs rb070d30_panel_funcs = {
153 .get_modes = rb070d30_panel_get_modes,
154 .prepare = rb070d30_panel_prepare,
155 .enable = rb070d30_panel_enable,
156 .disable = rb070d30_panel_disable,
157 .unprepare = rb070d30_panel_unprepare,
160 static int rb070d30_panel_dsi_probe(struct mipi_dsi_device *dsi)
162 struct rb070d30_panel *ctx;
165 ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
169 ctx->supply = devm_regulator_get(&dsi->dev, "vcc-lcd");
170 if (IS_ERR(ctx->supply))
171 return PTR_ERR(ctx->supply);
173 mipi_dsi_set_drvdata(dsi, ctx);
176 drm_panel_init(&ctx->panel);
177 ctx->panel.dev = &dsi->dev;
178 ctx->panel.funcs = &rb070d30_panel_funcs;
180 ctx->gpios.reset = devm_gpiod_get(&dsi->dev, "reset", GPIOD_OUT_LOW);
181 if (IS_ERR(ctx->gpios.reset)) {
182 DRM_DEV_ERROR(&dsi->dev, "Couldn't get our reset GPIO\n");
183 return PTR_ERR(ctx->gpios.reset);
186 ctx->gpios.power = devm_gpiod_get(&dsi->dev, "power", GPIOD_OUT_LOW);
187 if (IS_ERR(ctx->gpios.power)) {
188 DRM_DEV_ERROR(&dsi->dev, "Couldn't get our power GPIO\n");
189 return PTR_ERR(ctx->gpios.power);
193 * We don't change the state of that GPIO later on but we need
194 * to force it into a low state.
196 ctx->gpios.updn = devm_gpiod_get(&dsi->dev, "updn", GPIOD_OUT_LOW);
197 if (IS_ERR(ctx->gpios.updn)) {
198 DRM_DEV_ERROR(&dsi->dev, "Couldn't get our updn GPIO\n");
199 return PTR_ERR(ctx->gpios.updn);
203 * We don't change the state of that GPIO later on but we need
204 * to force it into a low state.
206 ctx->gpios.shlr = devm_gpiod_get(&dsi->dev, "shlr", GPIOD_OUT_LOW);
207 if (IS_ERR(ctx->gpios.shlr)) {
208 DRM_DEV_ERROR(&dsi->dev, "Couldn't get our shlr GPIO\n");
209 return PTR_ERR(ctx->gpios.shlr);
212 ctx->backlight = devm_of_find_backlight(&dsi->dev);
213 if (IS_ERR(ctx->backlight)) {
214 DRM_DEV_ERROR(&dsi->dev, "Couldn't get our backlight\n");
215 return PTR_ERR(ctx->backlight);
218 ret = drm_panel_add(&ctx->panel);
222 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | MIPI_DSI_MODE_LPM;
223 dsi->format = MIPI_DSI_FMT_RGB888;
226 return mipi_dsi_attach(dsi);
229 static int rb070d30_panel_dsi_remove(struct mipi_dsi_device *dsi)
231 struct rb070d30_panel *ctx = mipi_dsi_get_drvdata(dsi);
233 mipi_dsi_detach(dsi);
234 drm_panel_remove(&ctx->panel);
239 static const struct of_device_id rb070d30_panel_of_match[] = {
240 { .compatible = "ronbo,rb070d30" },
243 MODULE_DEVICE_TABLE(of, rb070d30_panel_of_match);
245 static struct mipi_dsi_driver rb070d30_panel_driver = {
246 .probe = rb070d30_panel_dsi_probe,
247 .remove = rb070d30_panel_dsi_remove,
249 .name = "panel-ronbo-rb070d30",
250 .of_match_table = rb070d30_panel_of_match,
253 module_mipi_dsi_driver(rb070d30_panel_driver);
255 MODULE_AUTHOR("Boris Brezillon <boris.brezillon@bootlin.com>");
256 MODULE_AUTHOR("Konstantin Sudakov <k.sudakov@integrasources.com>");
257 MODULE_DESCRIPTION("Ronbo RB070D30 Panel Driver");
258 MODULE_LICENSE("GPL");