1 // SPDX-License-Identifier: GPL-2.0+
3 * MIPI-DSI Samsung s6d16d0 panel driver. This is a 864x480
4 * AMOLED panel with a command-only DSI interface.
7 #include <drm/drm_modes.h>
8 #include <drm/drm_mipi_dsi.h>
9 #include <drm/drm_panel.h>
10 #include <drm/drm_print.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/regulator/consumer.h>
14 #include <linux/delay.h>
15 #include <linux/of_device.h>
16 #include <linux/module.h>
20 struct drm_panel panel;
21 struct regulator *supply;
22 struct gpio_desc *reset_gpio;
26 * The timings are not very helpful as the display is used in
29 static const struct drm_display_mode samsung_s6d16d0_mode = {
30 /* HS clock, (htotal*vtotal*vrefresh)/1000 */
33 .hsync_start = 864 + 154,
34 .hsync_end = 864 + 154 + 16,
35 .htotal = 864 + 154 + 16 + 32,
37 .vsync_start = 480 + 1,
38 .vsync_end = 480 + 1 + 1,
39 .vtotal = 480 + 1 + 1 + 1,
41 * This depends on the clocking HS vs LP rate, this value
43 * vrefresh = (clock * 1000) / (htotal*vtotal)
50 static inline struct s6d16d0 *panel_to_s6d16d0(struct drm_panel *panel)
52 return container_of(panel, struct s6d16d0, panel);
55 static int s6d16d0_unprepare(struct drm_panel *panel)
57 struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
58 struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
61 /* Enter sleep mode */
62 ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
64 DRM_DEV_ERROR(s6->dev, "failed to enter sleep mode (%d)\n",
70 gpiod_set_value_cansleep(s6->reset_gpio, 1);
71 regulator_disable(s6->supply);
76 static int s6d16d0_prepare(struct drm_panel *panel)
78 struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
79 struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
82 ret = regulator_enable(s6->supply);
84 DRM_DEV_ERROR(s6->dev, "failed to enable supply (%d)\n", ret);
89 gpiod_set_value_cansleep(s6->reset_gpio, 1);
92 gpiod_set_value_cansleep(s6->reset_gpio, 0);
95 /* Enabe tearing mode: send TE (tearing effect) at VBLANK */
96 ret = mipi_dsi_dcs_set_tear_on(dsi,
97 MIPI_DSI_DCS_TEAR_MODE_VBLANK);
99 DRM_DEV_ERROR(s6->dev, "failed to enable vblank TE (%d)\n",
103 /* Exit sleep mode and power on */
104 ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
106 DRM_DEV_ERROR(s6->dev, "failed to exit sleep mode (%d)\n",
114 static int s6d16d0_enable(struct drm_panel *panel)
116 struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
117 struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
120 ret = mipi_dsi_dcs_set_display_on(dsi);
122 DRM_DEV_ERROR(s6->dev, "failed to turn display on (%d)\n",
130 static int s6d16d0_disable(struct drm_panel *panel)
132 struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
133 struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
136 ret = mipi_dsi_dcs_set_display_off(dsi);
138 DRM_DEV_ERROR(s6->dev, "failed to turn display off (%d)\n",
146 static int s6d16d0_get_modes(struct drm_panel *panel,
147 struct drm_connector *connector)
149 struct drm_display_mode *mode;
151 mode = drm_mode_duplicate(connector->dev, &samsung_s6d16d0_mode);
153 DRM_ERROR("bad mode or failed to add mode\n");
156 drm_mode_set_name(mode);
157 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
159 connector->display_info.width_mm = mode->width_mm;
160 connector->display_info.height_mm = mode->height_mm;
162 drm_mode_probed_add(connector, mode);
164 return 1; /* Number of modes */
167 static const struct drm_panel_funcs s6d16d0_drm_funcs = {
168 .disable = s6d16d0_disable,
169 .unprepare = s6d16d0_unprepare,
170 .prepare = s6d16d0_prepare,
171 .enable = s6d16d0_enable,
172 .get_modes = s6d16d0_get_modes,
175 static int s6d16d0_probe(struct mipi_dsi_device *dsi)
177 struct device *dev = &dsi->dev;
181 s6 = devm_kzalloc(dev, sizeof(struct s6d16d0), GFP_KERNEL);
185 mipi_dsi_set_drvdata(dsi, s6);
189 dsi->format = MIPI_DSI_FMT_RGB888;
190 dsi->hs_rate = 420160000;
191 dsi->lp_rate = 19200000;
193 * This display uses command mode so no MIPI_DSI_MODE_VIDEO
194 * or MIPI_DSI_MODE_VIDEO_SYNC_PULSE
196 * As we only send commands we do not need to be continuously
200 MIPI_DSI_CLOCK_NON_CONTINUOUS |
201 MIPI_DSI_MODE_EOT_PACKET;
203 s6->supply = devm_regulator_get(dev, "vdd1");
204 if (IS_ERR(s6->supply))
205 return PTR_ERR(s6->supply);
207 /* This asserts RESET by default */
208 s6->reset_gpio = devm_gpiod_get_optional(dev, "reset",
210 if (IS_ERR(s6->reset_gpio)) {
211 ret = PTR_ERR(s6->reset_gpio);
212 if (ret != -EPROBE_DEFER)
213 DRM_DEV_ERROR(dev, "failed to request GPIO (%d)\n",
218 drm_panel_init(&s6->panel, dev, &s6d16d0_drm_funcs,
219 DRM_MODE_CONNECTOR_DSI);
221 ret = drm_panel_add(&s6->panel);
225 ret = mipi_dsi_attach(dsi);
227 drm_panel_remove(&s6->panel);
232 static int s6d16d0_remove(struct mipi_dsi_device *dsi)
234 struct s6d16d0 *s6 = mipi_dsi_get_drvdata(dsi);
236 mipi_dsi_detach(dsi);
237 drm_panel_remove(&s6->panel);
242 static const struct of_device_id s6d16d0_of_match[] = {
243 { .compatible = "samsung,s6d16d0" },
246 MODULE_DEVICE_TABLE(of, s6d16d0_of_match);
248 static struct mipi_dsi_driver s6d16d0_driver = {
249 .probe = s6d16d0_probe,
250 .remove = s6d16d0_remove,
252 .name = "panel-samsung-s6d16d0",
253 .of_match_table = s6d16d0_of_match,
256 module_mipi_dsi_driver(s6d16d0_driver);
258 MODULE_AUTHOR("Linus Wallei <linus.walleij@linaro.org>");
259 MODULE_DESCRIPTION("MIPI-DSI s6d16d0 Panel Driver");
260 MODULE_LICENSE("GPL v2");