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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* ams369fg06 AMOLED LCD panel driver.
*
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
* Author: Jingoo Han <jg1.han@samsung.com>
*
* Derived from drivers/video/s6e63m0.c
*/
#include <linux/backlight.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/gpio.h>
#include <linux/lcd.h>
#include <linux/module.h>
#include <linux/spi/spi.h>
#include <linux/wait.h>
#define SLEEPMSEC 0x1000
#define ENDDEF 0x2000
#define DEFMASK 0xFF00
#define COMMAND_ONLY 0xFE
#define DATA_ONLY 0xFF
#define MAX_GAMMA_LEVEL 5
#define GAMMA_TABLE_COUNT 21
#define MIN_BRIGHTNESS 0
#define MAX_BRIGHTNESS 255
#define DEFAULT_BRIGHTNESS 150
struct ams369fg06 {
struct device *dev;
struct spi_device *spi;
unsigned int power;
struct lcd_device *ld;
struct backlight_device *bd;
struct lcd_platform_data *lcd_pd;
};
static const unsigned short seq_display_on[] = {
0x14, 0x03,
ENDDEF, 0x0000
};
static const unsigned short seq_display_off[] = {
0x14, 0x00,
ENDDEF, 0x0000
};
static const unsigned short seq_stand_by_on[] = {
0x1D, 0xA1,
SLEEPMSEC, 200,
ENDDEF, 0x0000
};
static const unsigned short seq_stand_by_off[] = {
0x1D, 0xA0,
SLEEPMSEC, 250,
ENDDEF, 0x0000
};
static const unsigned short seq_setting[] = {
0x31, 0x08,
0x32, 0x14,
0x30, 0x02,
0x27, 0x01,
0x12, 0x08,
0x13, 0x08,
0x15, 0x00,
0x16, 0x00,
0xef, 0xd0,
DATA_ONLY, 0xe8,
0x39, 0x44,
0x40, 0x00,
0x41, 0x3f,
0x42, 0x2a,
0x43, 0x27,
0x44, 0x27,
0x45, 0x1f,
0x46, 0x44,
0x50, 0x00,
0x51, 0x00,
0x52, 0x17,
0x53, 0x24,
0x54, 0x26,
0x55, 0x1f,
0x56, 0x43,
0x60, 0x00,
0x61, 0x3f,
0x62, 0x2a,
0x63, 0x25,
0x64, 0x24,
0x65, 0x1b,
0x66, 0x5c,
0x17, 0x22,
0x18, 0x33,
0x19, 0x03,
0x1a, 0x01,
0x22, 0xa4,
0x23, 0x00,
0x26, 0xa0,
0x1d, 0xa0,
SLEEPMSEC, 300,
0x14, 0x03,
ENDDEF, 0x0000
};
/* gamma value: 2.2 */
static const unsigned int ams369fg06_22_250[] = {
0x00, 0x3f, 0x2a, 0x27, 0x27, 0x1f, 0x44,
0x00, 0x00, 0x17, 0x24, 0x26, 0x1f, 0x43,
0x00, 0x3f, 0x2a, 0x25, 0x24, 0x1b, 0x5c,
};
static const unsigned int ams369fg06_22_200[] = {
0x00, 0x3f, 0x28, 0x29, 0x27, 0x21, 0x3e,
0x00, 0x00, 0x10, 0x25, 0x27, 0x20, 0x3d,
0x00, 0x3f, 0x28, 0x27, 0x25, 0x1d, 0x53,
};
static const unsigned int ams369fg06_22_150[] = {
0x00, 0x3f, 0x2d, 0x29, 0x28, 0x23, 0x37,
0x00, 0x00, 0x0b, 0x25, 0x28, 0x22, 0x36,
0x00, 0x3f, 0x2b, 0x28, 0x26, 0x1f, 0x4a,
};
static const unsigned int ams369fg06_22_100[] = {
0x00, 0x3f, 0x30, 0x2a, 0x2b, 0x24, 0x2f,
0x00, 0x00, 0x00, 0x25, 0x29, 0x24, 0x2e,
0x00, 0x3f, 0x2f, 0x29, 0x29, 0x21, 0x3f,
};
static const unsigned int ams369fg06_22_50[] = {
0x00, 0x3f, 0x3c, 0x2c, 0x2d, 0x27, 0x24,
0x00, 0x00, 0x00, 0x22, 0x2a, 0x27, 0x23,
0x00, 0x3f, 0x3b, 0x2c, 0x2b, 0x24, 0x31,
};
struct ams369fg06_gamma {
unsigned int *gamma_22_table[MAX_GAMMA_LEVEL];
};
static struct ams369fg06_gamma gamma_table = {
.gamma_22_table[0] = (unsigned int *)&ams369fg06_22_50,
.gamma_22_table[1] = (unsigned int *)&ams369fg06_22_100,
.gamma_22_table[2] = (unsigned int *)&ams369fg06_22_150,
.gamma_22_table[3] = (unsigned int *)&ams369fg06_22_200,
.gamma_22_table[4] = (unsigned int *)&ams369fg06_22_250,
};
static int ams369fg06_spi_write_byte(struct ams369fg06 *lcd, int addr, int data)
{
u16 buf[1];
struct spi_message msg;
struct spi_transfer xfer = {
.len = 2,
.tx_buf = buf,
};
buf[0] = (addr << 8) | data;
spi_message_init(&msg);
spi_message_add_tail(&xfer, &msg);
return spi_sync(lcd->spi, &msg);
}
static int ams369fg06_spi_write(struct ams369fg06 *lcd, unsigned char address,
unsigned char command)
{
int ret = 0;
if (address != DATA_ONLY)
ret = ams369fg06_spi_write_byte(lcd, 0x70, address);
if (command != COMMAND_ONLY)
ret = ams369fg06_spi_write_byte(lcd, 0x72, command);
return ret;
}
static int ams369fg06_panel_send_sequence(struct ams369fg06 *lcd,
const unsigned short *wbuf)
{
int ret = 0, i = 0;
while ((wbuf[i] & DEFMASK) != ENDDEF) {
if ((wbuf[i] & DEFMASK) != SLEEPMSEC) {
ret = ams369fg06_spi_write(lcd, wbuf[i], wbuf[i+1]);
if (ret)
break;
} else {
msleep(wbuf[i+1]);
}
i += 2;
}
return ret;
}
static int _ams369fg06_gamma_ctl(struct ams369fg06 *lcd,
const unsigned int *gamma)
{
unsigned int i = 0;
int ret = 0;
for (i = 0 ; i < GAMMA_TABLE_COUNT / 3; i++) {
ret
|