WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / panel / panel-samsung-s6d16d0.c
blob4aac0d1573dd096bfd6af013780131d8f61c4286
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * MIPI-DSI Samsung s6d16d0 panel driver. This is a 864x480
4 * AMOLED panel with a command-only DSI interface.
5 */
7 #include <drm/drm_modes.h>
8 #include <drm/drm_mipi_dsi.h>
9 #include <drm/drm_panel.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/regulator/consumer.h>
13 #include <linux/delay.h>
14 #include <linux/of_device.h>
15 #include <linux/module.h>
17 struct s6d16d0 {
18 struct device *dev;
19 struct drm_panel panel;
20 struct regulator *supply;
21 struct gpio_desc *reset_gpio;
25 * The timings are not very helpful as the display is used in
26 * command mode.
28 static const struct drm_display_mode samsung_s6d16d0_mode = {
29 /* HS clock, (htotal*vtotal*vrefresh)/1000 */
30 .clock = 420160,
31 .hdisplay = 864,
32 .hsync_start = 864 + 154,
33 .hsync_end = 864 + 154 + 16,
34 .htotal = 864 + 154 + 16 + 32,
35 .vdisplay = 480,
36 .vsync_start = 480 + 1,
37 .vsync_end = 480 + 1 + 1,
38 .vtotal = 480 + 1 + 1 + 1,
39 .width_mm = 84,
40 .height_mm = 48,
43 static inline struct s6d16d0 *panel_to_s6d16d0(struct drm_panel *panel)
45 return container_of(panel, struct s6d16d0, panel);
48 static int s6d16d0_unprepare(struct drm_panel *panel)
50 struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
51 struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
52 int ret;
54 /* Enter sleep mode */
55 ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
56 if (ret) {
57 dev_err(s6->dev, "failed to enter sleep mode (%d)\n", ret);
58 return ret;
61 /* Assert RESET */
62 gpiod_set_value_cansleep(s6->reset_gpio, 1);
63 regulator_disable(s6->supply);
65 return 0;
68 static int s6d16d0_prepare(struct drm_panel *panel)
70 struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
71 struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
72 int ret;
74 ret = regulator_enable(s6->supply);
75 if (ret) {
76 dev_err(s6->dev, "failed to enable supply (%d)\n", ret);
77 return ret;
80 /* Assert RESET */
81 gpiod_set_value_cansleep(s6->reset_gpio, 1);
82 udelay(10);
83 /* De-assert RESET */
84 gpiod_set_value_cansleep(s6->reset_gpio, 0);
85 msleep(120);
87 /* Enabe tearing mode: send TE (tearing effect) at VBLANK */
88 ret = mipi_dsi_dcs_set_tear_on(dsi,
89 MIPI_DSI_DCS_TEAR_MODE_VBLANK);
90 if (ret) {
91 dev_err(s6->dev, "failed to enable vblank TE (%d)\n", ret);
92 return ret;
94 /* Exit sleep mode and power on */
95 ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
96 if (ret) {
97 dev_err(s6->dev, "failed to exit sleep mode (%d)\n", ret);
98 return ret;
101 return 0;
104 static int s6d16d0_enable(struct drm_panel *panel)
106 struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
107 struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
108 int ret;
110 ret = mipi_dsi_dcs_set_display_on(dsi);
111 if (ret) {
112 dev_err(s6->dev, "failed to turn display on (%d)\n", ret);
113 return ret;
116 return 0;
119 static int s6d16d0_disable(struct drm_panel *panel)
121 struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
122 struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
123 int ret;
125 ret = mipi_dsi_dcs_set_display_off(dsi);
126 if (ret) {
127 dev_err(s6->dev, "failed to turn display off (%d)\n", ret);
128 return ret;
131 return 0;
134 static int s6d16d0_get_modes(struct drm_panel *panel,
135 struct drm_connector *connector)
137 struct drm_display_mode *mode;
139 mode = drm_mode_duplicate(connector->dev, &samsung_s6d16d0_mode);
140 if (!mode) {
141 dev_err(panel->dev, "bad mode or failed to add mode\n");
142 return -EINVAL;
144 drm_mode_set_name(mode);
145 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
147 connector->display_info.width_mm = mode->width_mm;
148 connector->display_info.height_mm = mode->height_mm;
150 drm_mode_probed_add(connector, mode);
152 return 1; /* Number of modes */
155 static const struct drm_panel_funcs s6d16d0_drm_funcs = {
156 .disable = s6d16d0_disable,
157 .unprepare = s6d16d0_unprepare,
158 .prepare = s6d16d0_prepare,
159 .enable = s6d16d0_enable,
160 .get_modes = s6d16d0_get_modes,
163 static int s6d16d0_probe(struct mipi_dsi_device *dsi)
165 struct device *dev = &dsi->dev;
166 struct s6d16d0 *s6;
167 int ret;
169 s6 = devm_kzalloc(dev, sizeof(struct s6d16d0), GFP_KERNEL);
170 if (!s6)
171 return -ENOMEM;
173 mipi_dsi_set_drvdata(dsi, s6);
174 s6->dev = dev;
176 dsi->lanes = 2;
177 dsi->format = MIPI_DSI_FMT_RGB888;
178 dsi->hs_rate = 420160000;
179 dsi->lp_rate = 19200000;
181 * This display uses command mode so no MIPI_DSI_MODE_VIDEO
182 * or MIPI_DSI_MODE_VIDEO_SYNC_PULSE
184 * As we only send commands we do not need to be continuously
185 * clocked.
187 dsi->mode_flags =
188 MIPI_DSI_CLOCK_NON_CONTINUOUS |
189 MIPI_DSI_MODE_EOT_PACKET;
191 s6->supply = devm_regulator_get(dev, "vdd1");
192 if (IS_ERR(s6->supply))
193 return PTR_ERR(s6->supply);
195 /* This asserts RESET by default */
196 s6->reset_gpio = devm_gpiod_get_optional(dev, "reset",
197 GPIOD_OUT_HIGH);
198 if (IS_ERR(s6->reset_gpio)) {
199 ret = PTR_ERR(s6->reset_gpio);
200 if (ret != -EPROBE_DEFER)
201 dev_err(dev, "failed to request GPIO (%d)\n", ret);
202 return ret;
205 drm_panel_init(&s6->panel, dev, &s6d16d0_drm_funcs,
206 DRM_MODE_CONNECTOR_DSI);
208 drm_panel_add(&s6->panel);
210 ret = mipi_dsi_attach(dsi);
211 if (ret < 0)
212 drm_panel_remove(&s6->panel);
214 return ret;
217 static int s6d16d0_remove(struct mipi_dsi_device *dsi)
219 struct s6d16d0 *s6 = mipi_dsi_get_drvdata(dsi);
221 mipi_dsi_detach(dsi);
222 drm_panel_remove(&s6->panel);
224 return 0;
227 static const struct of_device_id s6d16d0_of_match[] = {
228 { .compatible = "samsung,s6d16d0" },
231 MODULE_DEVICE_TABLE(of, s6d16d0_of_match);
233 static struct mipi_dsi_driver s6d16d0_driver = {
234 .probe = s6d16d0_probe,
235 .remove = s6d16d0_remove,
236 .driver = {
237 .name = "panel-samsung-s6d16d0",
238 .of_match_table = s6d16d0_of_match,
241 module_mipi_dsi_driver(s6d16d0_driver);
243 MODULE_AUTHOR("Linus Wallei <linus.walleij@linaro.org>");
244 MODULE_DESCRIPTION("MIPI-DSI s6d16d0 Panel Driver");
245 MODULE_LICENSE("GPL v2");