10
10
#include <linux/fb.h>
11
11
#include <linux/kernel.h>
12
12
#include <linux/module.h>
13
+ #include <linux/of_device.h>
13
14
14
15
#include <linux/gpio/consumer.h>
15
16
#include <linux/regulator/consumer.h>
20
21
21
22
#include <video/mipi_display.h>
22
23
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
-
31
24
enum ili9881c_op {
32
25
ILI9881C_SWITCH_PAGE ,
33
26
ILI9881C_COMMAND ,
@@ -45,6 +38,21 @@ struct ili9881c_instr {
45
38
} arg ;
46
39
};
47
40
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
+
48
56
#define ILI9881C_SWITCH_PAGE_INSTR (_page ) \
49
57
{ \
50
58
.op = ILI9881C_SWITCH_PAGE, \
@@ -64,7 +72,7 @@ struct ili9881c_instr {
64
72
}, \
65
73
}
66
74
67
- static const struct ili9881c_instr ili9881c_init [] = {
75
+ static const struct ili9881c_instr lhr050h41_init [] = {
68
76
ILI9881C_SWITCH_PAGE_INSTR (3 ),
69
77
ILI9881C_COMMAND_INSTR (0x01 , 0x00 ),
70
78
ILI9881C_COMMAND_INSTR (0x02 , 0x00 ),
@@ -311,8 +319,8 @@ static int ili9881c_prepare(struct drm_panel *panel)
311
319
gpiod_set_value (ctx -> reset , 0 );
312
320
msleep (20 );
313
321
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 ];
316
324
317
325
if (instr -> op == ILI9881C_SWITCH_PAGE )
318
326
ret = ili9881c_switch_page (ctx , instr -> arg .page );
@@ -368,7 +376,7 @@ static int ili9881c_unprepare(struct drm_panel *panel)
368
376
return 0 ;
369
377
}
370
378
371
- static const struct drm_display_mode bananapi_default_mode = {
379
+ static const struct drm_display_mode lhr050h41_default_mode = {
372
380
.clock = 62000 ,
373
381
374
382
.hdisplay = 720 ,
@@ -380,6 +388,9 @@ static const struct drm_display_mode bananapi_default_mode = {
380
388
.vsync_start = 1280 + 10 ,
381
389
.vsync_end = 1280 + 10 + 10 ,
382
390
.vtotal = 1280 + 10 + 10 + 20 ,
391
+
392
+ .width_mm = 62 ,
393
+ .height_mm = 110 ,
383
394
};
384
395
385
396
static int ili9881c_get_modes (struct drm_panel * panel ,
@@ -388,12 +399,12 @@ static int ili9881c_get_modes(struct drm_panel *panel,
388
399
struct ili9881c * ctx = panel_to_ili9881c (panel );
389
400
struct drm_display_mode * mode ;
390
401
391
- mode = drm_mode_duplicate (connector -> dev , & bananapi_default_mode );
402
+ mode = drm_mode_duplicate (connector -> dev , ctx -> desc -> mode );
392
403
if (!mode ) {
393
404
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 ));
397
408
return - ENOMEM ;
398
409
}
399
410
@@ -402,8 +413,8 @@ static int ili9881c_get_modes(struct drm_panel *panel,
402
413
mode -> type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED ;
403
414
drm_mode_probed_add (connector , mode );
404
415
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 ;
407
418
408
419
return 1 ;
409
420
}
@@ -426,6 +437,7 @@ static int ili9881c_dsi_probe(struct mipi_dsi_device *dsi)
426
437
return - ENOMEM ;
427
438
mipi_dsi_set_drvdata (dsi , ctx );
428
439
ctx -> dsi = dsi ;
440
+ ctx -> desc = of_device_get_match_data (& dsi -> dev );
429
441
430
442
drm_panel_init (& ctx -> panel , & dsi -> dev , & ili9881c_funcs ,
431
443
DRM_MODE_CONNECTOR_DSI );
@@ -465,8 +477,14 @@ static int ili9881c_dsi_remove(struct mipi_dsi_device *dsi)
465
477
return 0 ;
466
478
}
467
479
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
+
468
486
static const struct of_device_id ili9881c_of_match [] = {
469
- { .compatible = "bananapi,lhr050h41" },
487
+ { .compatible = "bananapi,lhr050h41" , . data = & lhr050h41_desc },
470
488
{ }
471
489
};
472
490
MODULE_DEVICE_TABLE (of , ili9881c_of_match );
0 commit comments