Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (C) 2019, Michael Srba
3
4#include <linux/delay.h>
5#include <linux/gpio/consumer.h>
6#include <linux/module.h>
7#include <linux/of.h>
8#include <linux/regulator/consumer.h>
9
10#include <video/mipi_display.h>
11
12#include <drm/drm_mipi_dsi.h>
13#include <drm/drm_modes.h>
14#include <drm/drm_panel.h>
15
16struct s6e88a0_ams452ef01 {
17 struct drm_panel panel;
18 struct mipi_dsi_device *dsi;
19 struct regulator_bulk_data supplies[2];
20 struct gpio_desc *reset_gpio;
21};
22
23static inline struct
24s6e88a0_ams452ef01 *to_s6e88a0_ams452ef01(struct drm_panel *panel)
25{
26 return container_of(panel, struct s6e88a0_ams452ef01, panel);
27}
28
29static void s6e88a0_ams452ef01_reset(struct s6e88a0_ams452ef01 *ctx)
30{
31 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
32 usleep_range(5000, 6000);
33 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
34 usleep_range(1000, 2000);
35 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
36 usleep_range(10000, 11000);
37}
38
39static int s6e88a0_ams452ef01_on(struct s6e88a0_ams452ef01 *ctx)
40{
41 struct mipi_dsi_device *dsi = ctx->dsi;
42 struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
43
44 dsi->mode_flags |= MIPI_DSI_MODE_LPM;
45
46 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0x5a, 0x5a); // enable LEVEL2 commands
47 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xcc, 0x4c); // set Pixel Clock Divider polarity
48
49 mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
50 mipi_dsi_msleep(&dsi_ctx, 120);
51
52 // set default brightness/gama
53 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xca,
54 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,// V255 RR,GG,BB
55 0x80, 0x80, 0x80, // V203 R,G,B
56 0x80, 0x80, 0x80, // V151 R,G,B
57 0x80, 0x80, 0x80, // V87 R,G,B
58 0x80, 0x80, 0x80, // V51 R,G,B
59 0x80, 0x80, 0x80, // V35 R,G,B
60 0x80, 0x80, 0x80, // V23 R,G,B
61 0x80, 0x80, 0x80, // V11 R,G,B
62 0x6b, 0x68, 0x71, // V3 R,G,B
63 0x00, 0x00, 0x00); // V1 R,G,B
64 // set default Amoled Off Ratio
65 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb2, 0x40, 0x0a, 0x17, 0x00, 0x0a);
66 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb6, 0x2c, 0x0b); // set default elvss voltage
67 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MIPI_DCS_WRITE_POWER_SAVE, 0x00);
68 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf7, 0x03); // gamma/aor update
69 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0xa5, 0xa5); // disable LEVEL2 commands
70
71 mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
72
73 return dsi_ctx.accum_err;
74}
75
76static void s6e88a0_ams452ef01_off(struct s6e88a0_ams452ef01 *ctx)
77{
78 struct mipi_dsi_device *dsi = ctx->dsi;
79 struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi};
80
81 dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
82
83 mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
84 mipi_dsi_msleep(&dsi_ctx, 35);
85 mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
86 mipi_dsi_msleep(&dsi_ctx, 120);
87}
88
89static int s6e88a0_ams452ef01_prepare(struct drm_panel *panel)
90{
91 struct s6e88a0_ams452ef01 *ctx = to_s6e88a0_ams452ef01(panel);
92 int ret;
93
94 ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
95 if (ret < 0)
96 return ret;
97
98 s6e88a0_ams452ef01_reset(ctx);
99
100 ret = s6e88a0_ams452ef01_on(ctx);
101 if (ret < 0) {
102 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
103 regulator_bulk_disable(ARRAY_SIZE(ctx->supplies),
104 ctx->supplies);
105 return ret;
106 }
107
108 return 0;
109}
110
111static int s6e88a0_ams452ef01_unprepare(struct drm_panel *panel)
112{
113 struct s6e88a0_ams452ef01 *ctx = to_s6e88a0_ams452ef01(panel);
114
115 s6e88a0_ams452ef01_off(ctx);
116
117 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
118 regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
119
120 return 0;
121}
122
123static const struct drm_display_mode s6e88a0_ams452ef01_mode = {
124 .clock = (540 + 88 + 4 + 20) * (960 + 14 + 2 + 8) * 60 / 1000,
125 .hdisplay = 540,
126 .hsync_start = 540 + 88,
127 .hsync_end = 540 + 88 + 4,
128 .htotal = 540 + 88 + 4 + 20,
129 .vdisplay = 960,
130 .vsync_start = 960 + 14,
131 .vsync_end = 960 + 14 + 2,
132 .vtotal = 960 + 14 + 2 + 8,
133 .width_mm = 56,
134 .height_mm = 100,
135};
136
137static int s6e88a0_ams452ef01_get_modes(struct drm_panel *panel,
138 struct drm_connector *connector)
139{
140 struct drm_display_mode *mode;
141
142 mode = drm_mode_duplicate(connector->dev, &s6e88a0_ams452ef01_mode);
143 if (!mode)
144 return -ENOMEM;
145
146 drm_mode_set_name(mode);
147
148 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
149 connector->display_info.width_mm = mode->width_mm;
150 connector->display_info.height_mm = mode->height_mm;
151 drm_mode_probed_add(connector, mode);
152
153 return 1;
154}
155
156static const struct drm_panel_funcs s6e88a0_ams452ef01_panel_funcs = {
157 .unprepare = s6e88a0_ams452ef01_unprepare,
158 .prepare = s6e88a0_ams452ef01_prepare,
159 .get_modes = s6e88a0_ams452ef01_get_modes,
160};
161
162static int s6e88a0_ams452ef01_probe(struct mipi_dsi_device *dsi)
163{
164 struct device *dev = &dsi->dev;
165 struct s6e88a0_ams452ef01 *ctx;
166 int ret;
167
168 ctx = devm_drm_panel_alloc(dev, struct s6e88a0_ams452ef01, panel,
169 &s6e88a0_ams452ef01_panel_funcs,
170 DRM_MODE_CONNECTOR_DSI);
171 if (IS_ERR(ctx))
172 return PTR_ERR(ctx);
173
174 ctx->supplies[0].supply = "vdd3";
175 ctx->supplies[1].supply = "vci";
176 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
177 ctx->supplies);
178 if (ret < 0) {
179 dev_err(dev, "Failed to get regulators: %d\n", ret);
180 return ret;
181 }
182
183 ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
184 if (IS_ERR(ctx->reset_gpio)) {
185 ret = PTR_ERR(ctx->reset_gpio);
186 dev_err(dev, "Failed to get reset-gpios: %d\n", ret);
187 return ret;
188 }
189
190 ctx->dsi = dsi;
191 mipi_dsi_set_drvdata(dsi, ctx);
192
193 dsi->lanes = 2;
194 dsi->format = MIPI_DSI_FMT_RGB888;
195 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST;
196
197 drm_panel_add(&ctx->panel);
198
199 ret = mipi_dsi_attach(dsi);
200 if (ret < 0) {
201 dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
202 drm_panel_remove(&ctx->panel);
203 return ret;
204 }
205
206 return 0;
207}
208
209static void s6e88a0_ams452ef01_remove(struct mipi_dsi_device *dsi)
210{
211 struct s6e88a0_ams452ef01 *ctx = mipi_dsi_get_drvdata(dsi);
212 int ret;
213
214 ret = mipi_dsi_detach(dsi);
215 if (ret < 0)
216 dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
217
218 drm_panel_remove(&ctx->panel);
219}
220
221static const struct of_device_id s6e88a0_ams452ef01_of_match[] = {
222 { .compatible = "samsung,s6e88a0-ams452ef01" },
223 { /* sentinel */ },
224};
225MODULE_DEVICE_TABLE(of, s6e88a0_ams452ef01_of_match);
226
227static struct mipi_dsi_driver s6e88a0_ams452ef01_driver = {
228 .probe = s6e88a0_ams452ef01_probe,
229 .remove = s6e88a0_ams452ef01_remove,
230 .driver = {
231 .name = "panel-s6e88a0-ams452ef01",
232 .of_match_table = s6e88a0_ams452ef01_of_match,
233 },
234};
235module_mipi_dsi_driver(s6e88a0_ams452ef01_driver);
236
237MODULE_AUTHOR("Michael Srba <Michael.Srba@seznam.cz>");
238MODULE_DESCRIPTION("MIPI-DSI based Panel Driver for AMS452EF01 AMOLED LCD with a S6E88A0 controller");
239MODULE_LICENSE("GPL v2");