1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* BOE BF060Y8M-AJ0 5.99" MIPI-DSI OLED Panel on SW43404 DriverIC
*
* Copyright (c) 2020 AngeloGioacchino Del Regno
* <angelogioacchino.delregno@somainline.org>
*/
#include <linux/backlight.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/regulator/consumer.h>
#include <video/mipi_display.h>
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_modes.h>
#include <drm/drm_panel.h>
#define DCS_ALLOW_HBM_RANGE 0x0c
#define DCS_DISALLOW_HBM_RANGE 0x08
enum boe_bf060y8m_aj0_supplies {
BF060Y8M_VREG_VCC,
BF060Y8M_VREG_VDDIO,
BF060Y8M_VREG_VCI,
BF060Y8M_VREG_EL_VDD,
BF060Y8M_VREG_EL_VSS,
BF060Y8M_VREG_MAX
};
struct boe_bf060y8m_aj0 {
struct drm_panel panel;
struct mipi_dsi_device *dsi;
struct regulator_bulk_data vregs[BF060Y8M_VREG_MAX];
struct gpio_desc *reset_gpio;
bool prepared;
};
static inline
struct boe_bf060y8m_aj0 *to_boe_bf060y8m_aj0(struct drm_panel *panel)
{
return container_of(panel, struct boe_bf060y8m_aj0, panel);
}
static void boe_bf060y8m_aj0_reset(struct boe_bf060y8m_aj0 *boe)
{
gpiod_set_value_cansleep(boe->reset_gpio, 0);
usleep_range(2000, 3000);
gpiod_set_value_cansleep(boe->reset_gpio, 1);
usleep_range(15000, 16000);
gpiod_set_value_cansleep(boe->reset_gpio, 0);
usleep_range(5000, 6000);
}
static int boe_bf060y8m_aj0_on(struct boe_bf060y8m_aj0 *boe)
{
struct mipi_dsi_device *dsi = boe->dsi;
struct device *dev = &dsi->dev;
int ret;
mipi_dsi_dcs_write_seq(dsi, 0xb0, 0xa5, 0x00);
mipi_dsi_dcs_write_seq(dsi, 0xb2, 0x00, 0x4c);
mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_3D_CONTROL, 0x10);
mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_POWER_SAVE, DCS_ALLOW_HBM_RANGE);
mipi_dsi_dcs_write_seq(dsi, 0xf8,
0x00, 0x08, 0x10, 0x00, 0x22, 0x00, 0x00, 0x2d);
ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
if (ret < 0) {
dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
return ret;
}
msleep(30);
mipi_dsi_dcs_write_seq(dsi, 0xb0, 0xa5, 0x00);
mipi_dsi_dcs_write_seq(dsi, 0xc0,
0x08, 0x48, 0x65, 0x33, 0x33, 0x33,
0x2a, 0x31, 0x39, 0x20, 0x09);
mipi_dsi_dcs_write_seq(dsi, 0xc1, 0x00, 0x00, 0x00, 0x1f, 0x1f,
0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f);
mipi_dsi_dcs_write_seq(dsi, 0xe2, 0x20, 0x04, 0x10, 0x12, 0x92,
0x4f, 0x8f, 0x44, 0x84, 0x83, 0x83, 0x83,
0x5c, 0x5c, 0x5c);
mipi_dsi_dcs_write_seq(dsi, 0xde, 0x01, 0x2c, 0x00, 0x77, 0x3e);
msleep(30);
ret = mipi_dsi_dcs_set_display_on(dsi);
if (ret < 0) {
dev_err(dev, "Failed to set display on: %d\n", ret);
return ret;
}
msleep(50);
return 0;
}
static int boe_bf060y8m_aj0_off(struct boe_bf060y8m_aj0 *boe)
{
struct mipi_dsi_device *dsi = boe->dsi;
struct device *dev = &dsi->dev;
int ret;
/* OFF commands sent in HS mode */
dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
ret = mipi_dsi_dcs_set_display_off(dsi);
if (ret < 0) {
dev_err(dev, "Failed to set display off: %d\n", ret);
return ret;
}
msleep(20);
ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
if (ret < 0) {
dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
return ret;
}
usleep_range(1000, 2000);
dsi->mode_flags |= MIPI_DSI_MODE_LPM;
return 0;
}
static int boe_bf060y8m_aj0_prepare(struct drm_panel *panel)
{
struct boe_bf060y8m_aj0 *boe = to_boe_bf060y8m_aj0(panel);
struct device *dev = &boe->dsi->dev;
int ret;
if (boe->prepared)
return 0;
/*
* Enable EL Driving Voltage first - doing that at the beginning
* or at the end of the power sequence doesn't matter, so enable
* it here to avoid yet another usleep at the end.
*/
ret = regulator_enable(boe->vregs[BF060Y8M_VREG_EL_VDD].consumer);
if (ret)
return ret;
ret = regulator_enable(boe->vregs[BF060Y8M_VREG_EL_VSS].consumer);
if (ret)
goto err_elvss;
ret = regulator_enable(boe->vregs[BF060Y8M_VREG_VCC].consumer);
if (ret)
goto err_vcc;
usleep_range(1000, 2000);
ret = regulator_enable(boe->vregs[BF060Y8M_VREG_VDDIO].consumer);
if (ret)
goto err_vddio;
usleep_range(500, 1000);
ret = regulator_enable(boe->vregs[BF060Y8M_VREG_VCI].consumer);
if (ret)
goto err_vci;
usleep_range(2000, 3000);
boe_bf060y8m_aj0_reset(boe);
ret = boe_bf060y8m_aj0_on(boe);
if (ret < 0) {
dev_err(dev, "Failed to initialize panel: %d\n", ret);
gpiod_set_value_cansleep(boe->reset_gpio, 1);
return ret;
}
boe->prepared = true;
return 0;
err_vci:
regulator_disable(boe->vregs[BF060Y8M_VREG_VDDIO].consumer);
err_vddio:
regulator_disable(boe->vregs[BF060Y8M_VREG_VCC].consumer);
err_vcc:
regulator_disable(boe->vregs[BF060Y8M_VREG_EL_VSS].consumer);
err_elvss:
regulator_disable(boe->vregs[BF060Y8M_VREG_EL_VDD].consumer);
return ret;
}
static int boe_bf060y8m_aj0_unprepare(struct drm_panel *panel)
{
struct boe_bf060y8m_aj0 *boe = to_boe_bf060y8m_aj0(panel);
struct device *dev = &boe->dsi->dev;
int ret;
if (!boe->prepared)
return 0;
ret = boe_bf060y8m_aj0_off(boe);
if (ret < 0)
dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
gpiod_set_value_cansleep(boe->reset_gpio, 1);
ret = regulator_bulk_disable(ARRAY_SIZE(boe->vregs), boe->vregs);
boe->prepared = false;
return 0;
}
static const struct drm_display_mode boe_bf060y8m_aj0_mode = {
.clock = 165268,
.hdisplay = 1080,
.hsync_start = 1080 + 36,
.hsync_end = 1080 + 36 + 24,
.htotal = 1080 + 36 + 24 + 96,
.vdisplay = 2160,
.vsync_start = 2160 + 16,
.vsync_end = 2160 + 16 + 1,
.vtotal = 2160 + 16 + 1 + 15,
.width_mm = 68, /* 68.04 mm */
.height_mm = 136, /* 136.08 mm */
};
static int boe_bf060y8m_aj0_get_modes(struct drm_panel *panel,
struct drm_connector *connector)
{
struct drm_display_mode *mode;
mode = drm_mode_duplicate(connector->dev, &boe_bf060y8m_aj0_mode);
if (!mode)
return -ENOMEM;
drm_mode_set_name(mode);
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
connector->display_info.width_mm = mode->width_mm;
connector->display_info.height_mm = mode->height_mm;
drm_mode_probed_add(connector, mode);
return 1;
}
static const struct drm_panel_funcs boe_bf060y8m_aj0_panel_funcs = {
.prepare = boe_bf060y8m_aj0_prepare,
.unprepare = boe_bf060y8m_aj0_unprepare,
.get_modes = boe_bf060y8m_aj0_get_modes,
};
static int boe_bf060y8m_aj0_bl_update_status(struct backlight_device *bl)
{
struct mipi_dsi_device *dsi = bl_get_data(bl);
u16 brightness = backlight_get_brightness(bl);
int ret;
ret = mipi_dsi_dcs_set_display_brightness(dsi, brightness);
if (ret < 0)
return ret;
return 0;
}
static int boe_bf060y8m_aj0_bl_get_brightness(struct backlight_device *bl)
{
struct mipi_dsi_device *dsi = bl_get_data(bl);
u16 brightness;
int ret;
ret = mipi_dsi_dcs_get_display_brightness(dsi, &brightness);
if (ret < 0)
return ret;
return brightness & 0xff;
}
static const struct backlight_ops boe_bf060y8m_aj0_bl_ops = {
.update_status = boe_bf060y8m_aj0_bl_update_status,
.get_brightness = boe_bf060y8m_aj0_bl_get_brightness,
};
static struct backlight_device *
boe_bf060y8m_aj0_create_backlight(struct mipi_dsi_device *dsi)
{
struct device *dev = &dsi->dev;
const struct backlight_properties props = {
.type = BACKLIGHT_RAW,
.brightness = 127,
.max_brightness = 255,
.scale = BACKLIGHT_SCALE_NON_LINEAR,
};
return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
&boe_bf060y8m_aj0_bl_ops, &props);
}
static int boe_bf060y8m_aj0_init_vregs(struct boe_bf060y8m_aj0 *boe,
struct device *dev)
{
struct regulator *vreg;
int ret;
boe->vregs[BF060Y8M_VREG_VCC].supply = "vcc";
boe->vregs[BF060Y8M_VREG_VDDIO].supply = "vddio";
boe->vregs[BF060Y8M_VREG_VCI].supply = "vci";
boe->vregs[BF060Y8M_VREG_EL_VDD].supply = "elvdd";
boe->vregs[BF060Y8M_VREG_EL_VSS].supply = "elvss";
ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(boe->vregs),
boe->vregs);
if (ret < 0) {
dev_err(dev, "Failed to get regulators: %d\n", ret);
return ret;
}
vreg = boe->vregs[BF060Y8M_VREG_VCC].consumer;
ret = regulator_is_supported_voltage(vreg, 2700000, 3600000);
if (!ret)
return ret;
vreg = boe->vregs[BF060Y8M_VREG_VDDIO].consumer;
ret = regulator_is_supported_voltage(vreg, 1620000, 1980000);
if (!ret)
return ret;
vreg = boe->vregs[BF060Y8M_VREG_VCI].consumer;
ret = regulator_is_supported_voltage(vreg, 2600000, 3600000);
if (!ret)
return ret;
vreg = boe->vregs[BF060Y8M_VREG_EL_VDD].consumer;
ret = regulator_is_supported_voltage(vreg, 4400000, 4800000);
if (!ret)
return ret;
/* ELVSS is negative: -5.00V to -1.40V */
vreg = boe->vregs[BF060Y8M_VREG_EL_VSS].consumer;
ret = regulator_is_supported_voltage(vreg, 1400000, 5000000);
if (!ret)
return ret;
/*
* Set min/max rated current, known only for VCI and VDDIO and,
* in case of failure, just go on gracefully, as this step is not
* guaranteed to succeed on all regulator HW but do a debug print
* to inform the developer during debugging.
* In any case, these two supplies are also optional, so they may
* be fixed-regulator which, at the time of writing, does not
* support fake current limiting.
*/
vreg = boe->vregs[BF060Y8M_VREG_VDDIO].consumer;
ret = regulator_set_current_limit(vreg, 1500, 2500);
if (ret)
dev_dbg(dev, "Current limit cannot be set on %s: %d\n",
boe->vregs[1].supply, ret);
vreg = boe->vregs[BF060Y8M_VREG_VCI].consumer;
ret = regulator_set_current_limit(vreg, 20000, 40000);
if (ret)
dev_dbg(dev, "Current limit cannot be set on %s: %d\n",
boe->vregs[2].supply, ret);
return 0;
}
static int boe_bf060y8m_aj0_probe(struct mipi_dsi_device *dsi)
{
struct device *dev = &dsi->dev;
struct boe_bf060y8m_aj0 *boe;
int ret;
boe = devm_kzalloc(dev, sizeof(*boe), GFP_KERNEL);
if (!boe)
return -ENOMEM;
ret = boe_bf060y8m_aj0_init_vregs(boe, dev);
if (ret)
return dev_err_probe(dev, ret,
"Failed to initialize supplies.\n");
boe->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
if (IS_ERR(boe->reset_gpio))
return dev_err_probe(dev, PTR_ERR(boe->reset_gpio),
"Failed to get reset-gpios\n");
boe->dsi = dsi;
mipi_dsi_set_drvdata(dsi, boe);
dsi->lanes = 4;
dsi->format = MIPI_DSI_FMT_RGB888;
dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_NO_EOT_PACKET |
MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
MIPI_DSI_CLOCK_NON_CONTINUOUS |
MIPI_DSI_MODE_LPM;
drm_panel_init(&boe->panel, dev, &boe_bf060y8m_aj0_panel_funcs,
DRM_MODE_CONNECTOR_DSI);
boe->panel.backlight = boe_bf060y8m_aj0_create_backlight(dsi);
if (IS_ERR(boe->panel.backlight))
return dev_err_probe(dev, PTR_ERR(boe->panel.backlight),
"Failed to create backlight\n");
drm_panel_add(&boe->panel);
ret = mipi_dsi_attach(dsi);
if (ret < 0) {
dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
return ret;
}
return 0;
}
static void boe_bf060y8m_aj0_remove(struct mipi_dsi_device *dsi)
{
struct boe_bf060y8m_aj0 *boe = mipi_dsi_get_drvdata(dsi);
int ret;
ret = mipi_dsi_detach(dsi);
if (ret < 0)
dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
drm_panel_remove(&boe->panel);
}
static const struct of_device_id boe_bf060y8m_aj0_of_match[] = {
{ .compatible = "boe,bf060y8m-aj0" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, boe_bf060y8m_aj0_of_match);
static struct mipi_dsi_driver boe_bf060y8m_aj0_driver = {
.probe = boe_bf060y8m_aj0_probe,
.remove = boe_bf060y8m_aj0_remove,
.driver = {
.name = "panel-sw43404-boe-fhd-amoled",
.of_match_table = boe_bf060y8m_aj0_of_match,
},
};
module_mipi_dsi_driver(boe_bf060y8m_aj0_driver);
MODULE_AUTHOR("AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>");
MODULE_DESCRIPTION("BOE BF060Y8M-AJ0 MIPI-DSI OLED panel");
MODULE_LICENSE("GPL v2");
|