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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Driver for the Himax HX-8357 LCD Controller
*
* Copyright 2012 Free Electrons
*/
#include <linux/delay.h>
#include <linux/lcd.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <linux/spi/spi.h>
#define HX8357_NUM_IM_PINS 3
#define HX8357_SWRESET 0x01
#define HX8357_GET_RED_CHANNEL 0x06
#define HX8357_GET_GREEN_CHANNEL 0x07
#define HX8357_GET_BLUE_CHANNEL 0x08
#define HX8357_GET_POWER_MODE 0x0a
#define HX8357_GET_MADCTL 0x0b
#define HX8357_GET_PIXEL_FORMAT 0x0c
#define HX8357_GET_DISPLAY_MODE 0x0d
#define HX8357_GET_SIGNAL_MODE 0x0e
#define HX8357_GET_DIAGNOSTIC_RESULT 0x0f
#define HX8357_ENTER_SLEEP_MODE 0x10
#define HX8357_EXIT_SLEEP_MODE 0x11
#define HX8357_ENTER_PARTIAL_MODE 0x12
#define HX8357_ENTER_NORMAL_MODE 0x13
#define HX8357_EXIT_INVERSION_MODE 0x20
#define HX8357_ENTER_INVERSION_MODE 0x21
#define HX8357_SET_DISPLAY_OFF 0x28
#define HX8357_SET_DISPLAY_ON 0x29
#define HX8357_SET_COLUMN_ADDRESS 0x2a
#define HX8357_SET_PAGE_ADDRESS 0x2b
#define HX8357_WRITE_MEMORY_START 0x2c
#define HX8357_READ_MEMORY_START 0x2e
#define HX8357_SET_PARTIAL_AREA 0x30
#define HX8357_SET_SCROLL_AREA 0x33
#define HX8357_SET_TEAR_OFF 0x34
#define HX8357_SET_TEAR_ON 0x35
#define HX8357_SET_ADDRESS_MODE 0x36
#define HX8357_SET_SCROLL_START 0x37
#define HX8357_EXIT_IDLE_MODE 0x38
#define HX8357_ENTER_IDLE_MODE 0x39
#define HX8357_SET_PIXEL_FORMAT 0x3a
#define HX8357_SET_PIXEL_FORMAT_DBI_3BIT (0x1)
#define HX8357_SET_PIXEL_FORMAT_DBI_16BIT (0x5)
#define HX8357_SET_PIXEL_FORMAT_DBI_18BIT (0x6)
#define HX8357_SET_PIXEL_FORMAT_DPI_3BIT (0x1 << 4)
#define HX8357_SET_PIXEL_FORMAT_DPI_16BIT (0x5 << 4)
#define HX8357_SET_PIXEL_FORMAT_DPI_18BIT (0x6 << 4)
#define HX8357_WRITE_MEMORY_CONTINUE 0x3c
#define HX8357_READ_MEMORY_CONTINUE 0x3e
#define HX8357_SET_TEAR_SCAN_LINES 0x44
#define HX8357_GET_SCAN_LINES 0x45
#define HX8357_READ_DDB_START 0xa1
#define HX8357_SET_DISPLAY_MODE 0xb4
#define HX8357_SET_DISPLAY_MODE_RGB_THROUGH (0x3)
#define HX8357_SET_DISPLAY_MODE_RGB_INTERFACE (1 << 4)
#define HX8357_SET_PANEL_DRIVING 0xc0
#define HX8357_SET_DISPLAY_FRAME 0xc5
#define HX8357_SET_RGB 0xc6
#define HX8357_SET_RGB_ENABLE_HIGH (1 << 1)
#define HX8357_SET_GAMMA 0xc8
#define HX8357_SET_POWER 0xd0
#define HX8357_SET_VCOM 0xd1
#define HX8357_SET_POWER_NORMAL 0xd2
#define HX8357_SET_PANEL_RELATED 0xe9
#define HX8369_SET_DISPLAY_BRIGHTNESS 0x51
#define HX8369_WRITE_CABC_DISPLAY_VALUE 0x53
#define HX8369_WRITE_CABC_BRIGHT_CTRL 0x55
#define HX8369_WRITE_CABC_MIN_BRIGHTNESS 0x5e
#define HX8369_SET_POWER 0xb1
#define HX8369_SET_DISPLAY_MODE 0xb2
#define HX8369_SET_DISPLAY_WAVEFORM_CYC 0xb4
#define HX8369_SET_VCOM 0xb6
#define HX8369_SET_EXTENSION_COMMAND 0xb9
#define HX8369_SET_GIP 0xd5
#define HX8369_SET_GAMMA_CURVE_RELATED 0xe0
struct hx8357_data {
unsigned im_pins[HX8357_NUM_IM_PINS];
unsigned reset;
struct spi_device *spi;
int state;
bool use_im_pins;
};
static u8 hx8357_seq_power[] = {
HX8357_SET_POWER, 0x44, 0x41, 0x06,
};
static u8 hx8357_seq_vcom[] = {
HX8357_SET_VCOM, 0x40, 0x10,
};
static u8 hx8357_seq_power_normal[] = {
HX8357_SET_POWER_NORMAL, 0x05, 0x12,
};
static u8 hx8357_seq_panel_driving[] = {
HX8357_SET_PANEL_DRIVING, 0x14, 0x3b, 0x00, 0x02, 0x11,
};
static u8 hx8357_seq_display_frame[] = {
HX8357_SET_DISPLAY_FRAME, 0x0c,
};
static u8 hx8357_seq_panel_related[] = {
HX8357_SET_PANEL_RELATED, 0x01,
};
static u8 hx8357_seq_undefined1[] = {
0xea, 0x03, 0x00, 0x00,
};
static u8 hx8357_seq_undefined2[] = {
0xeb, 0x40, 0x54, 0x26, 0xdb,
};
static u8 hx8357_seq_gamma[] = {
HX8357_SET_GAMMA, 0x00, 0x15, 0x00, 0x22, 0x00,
0x08, 0x77, 0x26, 0x77, 0x22, 0x04, 0x00,
};
static u8 hx8357_seq_address_mode[] = {
HX8357_SET_ADDRESS_MODE, 0xc0,
};
static u8 hx8357_seq_pixel_format[] = {
HX8357_SET_PIXEL_FORMAT,
HX8357_SET_PIXEL_FORMAT_DPI_18BIT |
HX8357_SET_PIXEL_FORMAT_DBI_18BIT,
};
static u8 hx8357_seq_column_address[] = {
HX8357_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x01, 0x3f,
};
static u8 hx8357_seq_page_address[] = {
HX8357_SET_PAGE_ADDRESS, 0x00, 0x00, 0x01, 0xdf,
};
static u8 hx8357_seq_rgb[] = {
HX8357_SET_RGB, 0x02,
};
static u8 hx8357_seq_display_mode[] = {
HX8357_SET_DISPLAY_MODE,
HX8357_SET_DISPLAY_MODE_RGB_THROUGH |
HX8357_SET_DISPLAY_MODE_RGB_INTERFACE,
};
static u8 hx8369_seq_write_CABC_min_brightness[] = {
HX8369_WRITE_CABC_MIN_BRIGHTNESS, 0x00,
};
static u8 hx8369_seq_write_CABC_control[] = {
HX8369_WRITE_CABC_DISPLAY_VALUE, 0x24,
};
static u8 hx8369_seq_set_display_brightness[] = {
HX8369_SET_DISPLAY_BRIGHTNESS, 0xFF,
};
static u8 hx8369_seq_write_CABC_control_setting[] = {
HX8369_WRITE_CABC_BRIGHT_CTRL, 0x02,
};
static u8 hx8369_seq_extension_command[] = {
HX8369_SET_EXTENSION_COMMAND, 0xff, 0x83, 0x69,
};
static u8 hx8369_seq_display_related[] = {
HX8369_SET_DISPLAY_MODE, 0x00, 0x2b, 0x03, 0x03, 0x70, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x01,
};
static u8 hx8369_seq_panel_waveform_cycle[] = {
HX8369_SET_DISPLAY_WAVEFORM_CYC, 0x0a, 0x1d, 0x80, 0x06, 0x02,
};
static u8 hx8369_seq_set_address_mode[] = {
HX8357_SET_ADDRESS_MODE, 0x00,
};
static u8 hx8369_seq_vcom[] = {
HX8369_SET_VCOM, 0x3e, 0x3e,
};
static u8 hx8369_seq_gip[] = {
HX8369_SET_GIP, 0x00, 0x01, 0x03, 0x25, 0x01, 0x02, 0x28, 0x70,
0x11, 0x13, 0x00, 0x00, 0x40, 0x26, 0x51, 0x37, 0x00, 0x00, 0x71,
0x35, 0x60, 0x24, 0x07, 0x0f, 0x04, 0x04,
};
static u8 hx8369_seq_power[] = {
HX8369_SET_POWER, 0x01, 0x00, 0x34, 0x03, 0x00, 0x11, 0x11, 0x32,
0x2f, 0x3f, 0x3f, 0x01, 0x3a, 0x01, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6,
};
static u8 hx8369_seq_gamma_curve_related[] = {
HX8369_SET_GAMMA_CURVE_RELATED, 0x00, 0x0d, 0x19, 0x2f, 0x3b, 0x3d,
0x2e, 0x4a, 0x08, 0x0e, 0x0f, 0x14, 0x16, 0x14, 0x14, 0x14, 0x1e,
0x00, 0x0d, 0x19, 0x2f, 0x3b, 0x3d, 0x2e, 0x4a, 0x08, 0x0e, 0x0f,
0x14, 0x16, 0x14, 0x14, 0x14, 0x1e,
};
static int hx8357_spi_write_then_read(struct lcd_device *lcdev,
u8 *txbuf, u16 txlen,
u8 *rxbuf, u16 rxlen)
{
struct hx8357_data *lcd = lcd_get_data(lcdev);
struct spi_message msg;
struct spi_transfer xfer[2];
u16 *local_txbuf = NULL;
int ret = 0;
memset(xfer, 0, sizeof(xfer));
spi_message_init(&msg);
if (txlen) {
int i;
local_txbuf = kcalloc(txlen, sizeof(*local_txbuf), GFP_KERNEL);
if (!local_txbuf)
return -ENOMEM;
for (i = 0; i < txlen; i++) {
local_txbuf[i] = txbuf[i];
if (i >
|