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
|
#include <linux/kernel.h>
#include <linux/bug.h>
#include <linux/delay.h>
#include "../sprdfb_panel.h"
#include <mach/gpio.h>
#define LCD_DEBUG
#ifdef LCD_DEBUG
#define LCD_PRINT printk
#else
#define LCD_PRINT(...)
#endif
#define MAX_DATA 100
typedef struct LCM_Init_Code_tag {
unsigned int tag;
unsigned char data[MAX_DATA];
}LCM_Init_Code;
typedef struct LCM_force_cmd_code_tag{
unsigned int datatype;
LCM_Init_Code real_cmd_code;
}LCM_Force_Cmd_Code;
#define LCM_TAG_SHIFT 24
#define LCM_TAG_MASK ((1 << 24) -1)
#define LCM_SEND(len) ((1 << LCM_TAG_SHIFT)| len)
#define LCM_SLEEP(ms) ((2 << LCM_TAG_SHIFT)| ms)
//#define ARRAY_SIZE(array) ( sizeof(array) / sizeof(array[0]))
#define LCM_TAG_SEND (1<< 0)
#define LCM_TAG_SLEEP (1 << 1)
static LCM_Init_Code init_data[] = {
//Power setting Sequence
{LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x08,0x01}},
{LCM_SEND(4),{2,0,0xB0,0x08}},
{LCM_SEND(4),{2,0,0xB2,0x40}},
{LCM_SEND(4),{2,0,0xB3,0x28}},
{LCM_SEND(4),{2,0,0xB4,0x19}},
{LCM_SEND(4),{2,0,0xB5,0x54}},
{LCM_SEND(4),{2,0,0xB9,0x36}},
{LCM_SEND(4),{2,0,0xBA,0x024}},
{LCM_SEND(5),{3,0,0xBC,0xA0,0x00}},
{LCM_SEND(5),{3,0,0xBD,0xA0,0x00}},
//gamma setting
{LCM_SEND(19),{17,0,0xD1,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},
{LCM_SEND(19),{17,0,0xD2,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},
{LCM_SEND(19),{17,0,0xD3,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},
{LCM_SEND(7),{5,0,0xD4,0x03,0x5A,0x03,0x9A}},
{LCM_SEND(19),{17,0,0xD5,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},
{LCM_SEND(19),{17,0,0xD6,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},
{LCM_SEND(19),{17,0,0xD7,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},
{LCM_SEND(7),{5,0,0xD8,0x03,0x5A,0x03,0x9A}},
{LCM_SEND(19),{17,0,0xD9,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},
{LCM_SEND(19),{17,0,0xDD,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},
{LCM_SEND(19),{17,0,0xDE,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},
{LCM_SEND(7),{5,0,0xDF,0x03,0x5A,0x03,0x9A}},
{LCM_SEND(19),{17,0,0xE0,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},
{LCM_SEND(19),{17,0,0xE1,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},
{LCM_SEND(19),{17,0,0xE2,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},
{LCM_SEND(7),{5,0,0xE3,0x03,0x5A,0x03,0x9A}},
{LCM_SEND(19),{17,0,0xE4,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},
{LCM_SEND(19),{17,0,0xE5,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},
{LCM_SEND(19),{17,0,0xE6,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},
{LCM_SEND(7),{5,0,0xE7,0x03,0x5A,0x03,0x9A}},
{LCM_SEND(19),{17,0,0xE8,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},
{LCM_SEND(19),{17,0,0xE9,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},
{LCM_SEND(19),{17,0,0xEA,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},
{LCM_SEND(7),{5,0,0xEB,0x03,0x5A,0x03,0x9A}},
//initializing sequence
{LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x08,0x00}},
{LCM_SEND(5),{3,0,0xB1,0x16,0x08}},
{LCM_SEND(5),{3,0,0xB4,0x08,0x50}},
{LCM_SEND(4),{2,0,0xB6,0x03}},
{LCM_SEND(5),{3,0,0xB7,0x70,0x70}},
{LCM_SEND(5),{3,0,0xB8,0x61,0x66}},
{LCM_SEND(4),{2,0,0xBC,0x02}},
{LCM_SEND(21),{19,0,0xC8,0x80,0x00,0x46,0x64,0x46,0x64,0x46,0x64,0x46,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64}},
{LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x00,0x00}},
{LCM_SEND(7),{5,0,0xFF,0xAA,0x55,0x25,0x01}},
{LCM_SEND(4),{2,0,0x6F,0x02}},
{LCM_SEND(4),{2,0,0xF4,0x57}},
{LCM_SEND(6),{4,0,0xAA,0x55,0x25,0x00}},
{LCM_SEND(4),{2,0,0x36,0x00}},
{LCM_SEND(4),{2,0,0x35,0x00}},
{LCM_SEND(4),{2,0,0x0B,0xD8}},
//Display on
{LCM_SEND(1),{0x11}},
{LCM_SLEEP(120)},
{LCM_SEND(1),{0x29}},
{LCM_SLEEP(100)},
};
static LCM_Init_Code disp_on[] = {
{LCM_SEND(1),{0x11}},
{LCM_SLEEP(120)},
{LCM_SEND(1),{0x29}},
{LCM_SLEEP(100)},
};
static LCM_Init_Code sleep_in[] = {
{LCM_SEND(1), {0x28}},
{LCM_SLEEP(150)}, //>150ms
{LCM_SEND(1), {0x10}},
{LCM_SLEEP(150)}, //>150ms
};
static LCM_Init_Code sleep_out[] = {
{LCM_SEND(1), {0x11}},
{LCM_SLEEP(120)},//>120ms
{LCM_SEND(1), {0x29}},
{LCM_SLEEP(20)}, //>20ms
};
static int32_t nt35502_mipi_init(struct panel_spec *self)
{
int32_t i;
LCM_Init_Code *init = init_data;
unsigned int tag;
mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;
mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
printk("kernel nt35502_mipi_init\n");
mipi_set_cmd_mode();
mipi_eotp_set(0,0);
for(i = 0; i < ARRAY_SIZE(init_data); i++){
tag = (init->tag >>24);
if(tag & LCM_TAG_SEND){
mipi_dcs_write(init->data, (init->tag & LCM_TAG_MASK));
udelay(20);
}else if(tag & LCM_TAG_SLEEP){
msleep(init->tag & LCM_TAG_MASK);
}
init++;
}
mipi_eotp_set(0,0);
return 0;
}
static uint32_t nt35502_readid(struct panel_spec *self)
{
int32_t j =0;
uint8_t read_data[4] = {0};
int32_t read_rtn = 0;
uint8_t param[2] = {0};
mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
mipi_force_write_t mipi_force_write = self->info.mipi->ops->mipi_force_write;
mipi_force_read_t mipi_force_read = self->info.mipi->ops->mipi_force_read;
mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
LCD_PRINT("kernel lcd_nt35502_mipi read id!\n");
mipi_set_cmd_mode();
mipi_eotp_set(0,0);
for(j = 0; j < 4; j++){
param[0] = 0x01;
param[1] = 0x00;
mipi_force_write(0x04, param, 2);
read_rtn = mipi_force_read(0xda,1,&read_data[0]);
LCD_PRINT("lcd_nt35502_mipi read id 0xda value is 0x%x!\n",read_data[0]);
read_rtn = mipi_force_read(0xdb,1,&read_data[1]);
LCD_PRINT("lcd_nt35502_mipi read id 0xdb value is 0x%x!\n",read_data[1]);
read_rtn = mipi_force_read(0xdc,1,&read_data[2]);
LCD_PRINT("lcd_nt35502_mipi read id 0xdc value is 0x%x!\n",read_data[2]);
// if((0x55 == read_data[0])&&(0xbc == read_data[1])&&(0x90 == read_data[2])){
printk("lcd_nt35502_mipi read id success!\n");
return 0x8370;
// }
}
mipi_eotp_set(0,0);
return 0;
}
static int32_t nt35502_enter_sleep(struct panel_spec *self, uint8_t is_sleep)
{
int32_t i;
LCM_Init_Code *sleep_in_out = NULL;
unsigned int tag;
int32_t size = 0;
mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;
mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
printk("kernel nt35502_enter_sleep, is_sleep = %d\n", is_sleep);
if(is_sleep){
sleep_in_out = sleep_in;
size = ARRAY_SIZE(sleep_in);
}else{
sleep_in_out = sleep_out;
size = ARRAY_SIZE(sleep_out);
}
mipi_set_cmd_mode();
mipi_eotp_set(0,0);
for(i = 0; i <size ; i++){
tag = (sleep_in_out->tag >>24);
if(tag & LCM_TAG_SEND){
mipi_dcs_write(sleep_in_out->data, (sleep_in_out->tag & LCM_TAG_MASK));
}else if(tag & LCM_TAG_SLEEP){
msleep(sleep_in_out->tag & LCM_TAG_MASK);
}
sleep_in_out++;
}
mipi_eotp_set(0,0);
return 0;
}
static struct panel_operations lcd_nt35502_mipi_operations = {
.panel_init = nt35502_mipi_init,
.panel_readid = nt35502_readid,
.panel_enter_sleep = nt35502_enter_sleep,
};
static struct timing_rgb lcd_nt35502_mipi_timing = {
.hfp = 160, /* unit: pixel */
.hbp = 20,
.hsync = 20,
.vfp = 1, /*unit: line*/
.vbp = 11,
.vsync = 4,
};
static struct info_mipi lcd_nt35502_mipi_info = {
.work_mode = SPRDFB_MIPI_MODE_VIDEO,
.video_bus_width = 24, /*18,16*/
.lan_number = 2,
.phy_feq =500*1000,
.h_sync_pol = SPRDFB_POLARITY_POS,
.v_sync_pol = SPRDFB_POLARITY_POS,
.de_pol = SPRDFB_POLARITY_POS,
.te_pol = SPRDFB_POLARITY_POS,
.color_mode_pol = SPRDFB_POLARITY_NEG,
.shut_down_pol = SPRDFB_POLARITY_NEG,
.timing = &lcd_nt35502_mipi_timing,
.ops = NULL,
};
struct panel_spec lcd_nt35502_mipi_spec = {
.width = 480,
.height = 800,
.fps = 62,
.type = LCD_MODE_DSI,
.direction = LCD_DIRECT_NORMAL,
.info = {
.mipi = &lcd_nt35502_mipi_info
},
.ops = &lcd_nt35502_mipi_operations,
};
struct panel_cfg lcd_nt35502_mipi = {
/* this panel can only be main lcd */
.dev_id = SPRDFB_MAINLCD_ID,
.lcd_id = 0x8370,
.lcd_name = "lcd_nt35502_mipi",
.panel = &lcd_nt35502_mipi_spec,
};
//temp code
static int __init lcd_nt35502_mipi_init(void)
{
/*
printk("nt35502_mipi_init: set lcd backlight.\n");
if (gpio_request(214, "LCD_BL")) {
printk("Failed ro request LCD_BL GPIO_%d \n",
214);
return -ENODEV;
}
gpio_direction_output(214, 1);
gpio_set_value(214, 1);
*/
return sprdfb_panel_register(&lcd_nt35502_mipi);
}
subsys_initcall(lcd_nt35502_mipi_init);
|