Skip to content

Commit b7d71b6

Browse files
Icenowysravnborg
authored andcommitted
drm/panel: ilitek-ili9881c: prepare for adding support for extra panels
There're more panels with ILI9881C controller than the Bananapi one supported by this driver. Extract the mode and init sequence part, to prepare the driver for adding new panels. Signed-off-by: Icenowy Zheng <[email protected]> Signed-off-by: Sam Ravnborg <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e6c21e6 commit b7d71b6

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

drivers/gpu/drm/panel/panel-ilitek-ili9881c.c

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/fb.h>
1111
#include <linux/kernel.h>
1212
#include <linux/module.h>
13+
#include <linux/of_device.h>
1314

1415
#include <linux/gpio/consumer.h>
1516
#include <linux/regulator/consumer.h>
@@ -20,14 +21,6 @@
2021

2122
#include <video/mipi_display.h>
2223

23-
struct ili9881c {
24-
struct drm_panel panel;
25-
struct mipi_dsi_device *dsi;
26-
27-
struct regulator *power;
28-
struct gpio_desc *reset;
29-
};
30-
3124
enum ili9881c_op {
3225
ILI9881C_SWITCH_PAGE,
3326
ILI9881C_COMMAND,
@@ -45,6 +38,21 @@ struct ili9881c_instr {
4538
} arg;
4639
};
4740

41+
struct ili9881c_desc {
42+
const struct ili9881c_instr *init;
43+
const size_t init_length;
44+
const struct drm_display_mode *mode;
45+
};
46+
47+
struct ili9881c {
48+
struct drm_panel panel;
49+
struct mipi_dsi_device *dsi;
50+
const struct ili9881c_desc *desc;
51+
52+
struct regulator *power;
53+
struct gpio_desc *reset;
54+
};
55+
4856
#define ILI9881C_SWITCH_PAGE_INSTR(_page) \
4957
{ \
5058
.op = ILI9881C_SWITCH_PAGE, \
@@ -64,7 +72,7 @@ struct ili9881c_instr {
6472
}, \
6573
}
6674

67-
static const struct ili9881c_instr ili9881c_init[] = {
75+
static const struct ili9881c_instr lhr050h41_init[] = {
6876
ILI9881C_SWITCH_PAGE_INSTR(3),
6977
ILI9881C_COMMAND_INSTR(0x01, 0x00),
7078
ILI9881C_COMMAND_INSTR(0x02, 0x00),
@@ -311,8 +319,8 @@ static int ili9881c_prepare(struct drm_panel *panel)
311319
gpiod_set_value(ctx->reset, 0);
312320
msleep(20);
313321

314-
for (i = 0; i < ARRAY_SIZE(ili9881c_init); i++) {
315-
const struct ili9881c_instr *instr = &ili9881c_init[i];
322+
for (i = 0; i < ctx->desc->init_length; i++) {
323+
const struct ili9881c_instr *instr = &ctx->desc->init[i];
316324

317325
if (instr->op == ILI9881C_SWITCH_PAGE)
318326
ret = ili9881c_switch_page(ctx, instr->arg.page);
@@ -368,7 +376,7 @@ static int ili9881c_unprepare(struct drm_panel *panel)
368376
return 0;
369377
}
370378

371-
static const struct drm_display_mode bananapi_default_mode = {
379+
static const struct drm_display_mode lhr050h41_default_mode = {
372380
.clock = 62000,
373381

374382
.hdisplay = 720,
@@ -380,6 +388,9 @@ static const struct drm_display_mode bananapi_default_mode = {
380388
.vsync_start = 1280 + 10,
381389
.vsync_end = 1280 + 10 + 10,
382390
.vtotal = 1280 + 10 + 10 + 20,
391+
392+
.width_mm = 62,
393+
.height_mm = 110,
383394
};
384395

385396
static int ili9881c_get_modes(struct drm_panel *panel,
@@ -388,12 +399,12 @@ static int ili9881c_get_modes(struct drm_panel *panel,
388399
struct ili9881c *ctx = panel_to_ili9881c(panel);
389400
struct drm_display_mode *mode;
390401

391-
mode = drm_mode_duplicate(connector->dev, &bananapi_default_mode);
402+
mode = drm_mode_duplicate(connector->dev, ctx->desc->mode);
392403
if (!mode) {
393404
dev_err(&ctx->dsi->dev, "failed to add mode %ux%ux@%u\n",
394-
bananapi_default_mode.hdisplay,
395-
bananapi_default_mode.vdisplay,
396-
drm_mode_vrefresh(&bananapi_default_mode));
405+
ctx->desc->mode->hdisplay,
406+
ctx->desc->mode->vdisplay,
407+
drm_mode_vrefresh(ctx->desc->mode));
397408
return -ENOMEM;
398409
}
399410

@@ -402,8 +413,8 @@ static int ili9881c_get_modes(struct drm_panel *panel,
402413
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
403414
drm_mode_probed_add(connector, mode);
404415

405-
connector->display_info.width_mm = 62;
406-
connector->display_info.height_mm = 110;
416+
connector->display_info.width_mm = mode->width_mm;
417+
connector->display_info.height_mm = mode->height_mm;
407418

408419
return 1;
409420
}
@@ -426,6 +437,7 @@ static int ili9881c_dsi_probe(struct mipi_dsi_device *dsi)
426437
return -ENOMEM;
427438
mipi_dsi_set_drvdata(dsi, ctx);
428439
ctx->dsi = dsi;
440+
ctx->desc = of_device_get_match_data(&dsi->dev);
429441

430442
drm_panel_init(&ctx->panel, &dsi->dev, &ili9881c_funcs,
431443
DRM_MODE_CONNECTOR_DSI);
@@ -465,8 +477,14 @@ static int ili9881c_dsi_remove(struct mipi_dsi_device *dsi)
465477
return 0;
466478
}
467479

480+
static const struct ili9881c_desc lhr050h41_desc = {
481+
.init = lhr050h41_init,
482+
.init_length = ARRAY_SIZE(lhr050h41_init),
483+
.mode = &lhr050h41_default_mode,
484+
};
485+
468486
static const struct of_device_id ili9881c_of_match[] = {
469-
{ .compatible = "bananapi,lhr050h41" },
487+
{ .compatible = "bananapi,lhr050h41", .data = &lhr050h41_desc },
470488
{ }
471489
};
472490
MODULE_DEVICE_TABLE(of, ili9881c_of_match);

0 commit comments

Comments
 (0)