ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / transmitter / mipi_dsi.c
1 /*
2  * Copyright (C) 2013 ROCKCHIP, Inc.
3  * drivers/video/display/transmitter/mipi_dsi.c
4  * author: hhb@rock-chips.com
5  * create date: 2013-01-17
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15 #ifndef CONFIG_MIPI_DSI
16 #include <common.h>
17 #endif
18 #ifdef CONFIG_RK_3288_DSI_UBOOT
19 #include <asm/io.h>
20 #include <errno.h>
21 #include <malloc.h>
22 #include <fdtdec.h>
23 #include <errno.h>
24 #include <asm/io.h>
25 #include <asm/arch/rkplat.h>
26 #include <lcd.h>
27 #include "mipi_dsi.h"
28 #else
29 #include <linux/module.h>
30 #include <linux/init.h>
31 /* #include <asm/system.h> */
32 #include <linux/fb.h>
33 #include <linux/delay.h>
34 #include <linux/rk_fb.h>
35 #include <linux/rk_screen.h>
36 #include <linux/ktime.h>
37
38 #include "mipi_dsi.h"
39 #endif
40
41 #define MAX_DSI_CHIPS 5
42
43 /*
44 *                        Driver Version Note
45 *
46 *v1.0 : this driver is a top level architecture of mipi dsi driver;
47 *v1.1 : add struct mipi_dsi_screen
48 *v1.2 : add id argument to identify different dsi 
49 *v1.3 : fix send commad's methods  
50 */
51 #define MIPI_DSI_VERSION_AND_TIME  "mipi_dsi v1.3 2014-04-17"
52 #ifdef CONFIG_RK_3288_DSI_UBOOT
53 #define printk(x...)    printf(x)
54 #endif
55
56
57 static struct mipi_dsi_ops *dsi_ops[MAX_DSI_CHIPS] = {NULL};
58 //static struct mipi_dsi_ops *cur_dsi_ops;
59
60 int register_dsi_ops(unsigned int id, struct mipi_dsi_ops *ops) {
61
62         //int i = 0;
63         if(id > (MAX_DSI_CHIPS - 1))
64                 return -EINVAL;
65
66         dsi_ops[id] = ops;
67         return 0;
68 }
69 #ifdef CONFIG_MIPI_DSI
70 EXPORT_SYMBOL(register_dsi_ops);
71 #endif
72
73 int del_dsi_ops(struct mipi_dsi_ops *ops) {
74
75         int i = 0;
76
77         for(i = 0; i < MAX_DSI_CHIPS; i++) {
78                 if(dsi_ops[i] == ops) {
79                         dsi_ops[i] = NULL;
80                         break;  
81                 }       
82         }
83
84         if(i == MAX_DSI_CHIPS) {
85                 printk("dsi ops not found\n");
86                 return -1;
87         }
88         return 0;       
89 }
90 #ifdef CONFIG_MIPI_DSI
91 EXPORT_SYMBOL(del_dsi_ops);
92 #endif
93
94 int dsi_probe_current_chip(unsigned int id) {
95         struct mipi_dsi_ops *ops = NULL;
96
97         if(id > (MAX_DSI_CHIPS - 1))
98                 return -EINVAL;
99
100         ops = dsi_ops[id];
101         if(!ops)
102                 return -EINVAL;
103
104         id = ops->get_id(ops->dsi);
105
106         return id;
107 }
108 #ifdef CONFIG_MIPI_DSI
109 EXPORT_SYMBOL(dsi_probe_current_chip);
110 #endif
111 int dsi_power_up(unsigned int id) {
112
113         struct mipi_dsi_ops *ops = NULL;
114
115         if(id > (MAX_DSI_CHIPS - 1))
116                 return -EINVAL;
117
118         ops = dsi_ops[id];
119
120         if(!ops)
121                 return -EINVAL;
122         if(ops->power_up)
123                 ops->power_up(ops->dsi);
124         return 0;
125 }
126 #ifdef CONFIG_MIPI_DSI
127 EXPORT_SYMBOL(dsi_power_up);
128 #endif
129
130 int dsi_power_off(unsigned int id) {
131
132         struct mipi_dsi_ops *ops = NULL;
133
134         if(id > (MAX_DSI_CHIPS - 1))
135                 return -EINVAL;
136
137         ops = dsi_ops[id];
138
139         if(!ops)
140                 return -EINVAL;
141
142         if(ops->power_down)
143                 ops->power_down(ops->dsi);
144
145         return 0;
146 }
147 #ifdef CONFIG_MIPI_DSI
148 EXPORT_SYMBOL(dsi_power_off);
149 #endif
150 int dsi_set_regs(unsigned int id, void *array, u32 n) {
151
152         struct mipi_dsi_ops *ops = NULL;
153
154         if(id > (MAX_DSI_CHIPS - 1))
155                 return -EINVAL;
156
157         ops = dsi_ops[id];
158
159         if(!ops)
160                 return -EINVAL;
161
162         if(ops->dsi_set_regs)
163                 ops->dsi_set_regs(ops->dsi, array, n);
164
165         return 0;
166 }
167 #ifdef CONFIG_MIPI_DSI
168 EXPORT_SYMBOL(dsi_set_regs);
169 #endif
170 int dsi_init(unsigned int id, u32 n) {
171
172         struct mipi_dsi_ops *ops = NULL;
173
174         if(id > (MAX_DSI_CHIPS - 1))
175                 return -EINVAL;
176
177         ops = dsi_ops[id];
178
179         if(!ops)
180                 return -EINVAL;
181
182         if(ops->dsi_init)
183                 ops->dsi_init(ops->dsi, n);
184
185         return 0;
186 }
187 #ifdef CONFIG_MIPI_DSI
188 EXPORT_SYMBOL(dsi_init);
189 #endif
190 int dsi_enable_video_mode(unsigned int id, u32 enable) {
191
192         struct mipi_dsi_ops *ops = NULL;
193
194         if(id > (MAX_DSI_CHIPS - 1))
195                 return -EINVAL;
196
197         ops = dsi_ops[id];
198
199         if(!ops)
200                 return -EINVAL;
201
202         if(ops->dsi_enable_video_mode)
203                 ops->dsi_enable_video_mode(ops->dsi, enable);
204
205         return 0;
206
207 }
208 #ifdef CONFIG_MIPI_DSI
209 EXPORT_SYMBOL(dsi_enable_video_mode);
210 #endif
211 int dsi_enable_command_mode(unsigned int id, u32 enable) {
212
213         struct mipi_dsi_ops *ops = NULL;
214
215         if(id > (MAX_DSI_CHIPS - 1))
216                 return -EINVAL;
217
218         ops = dsi_ops[id];
219
220         if(!ops)
221                 return -EINVAL;
222
223         if(ops->dsi_enable_command_mode)
224                 ops->dsi_enable_command_mode(ops->dsi, enable);
225
226         return 0;
227
228 }
229 #ifdef CONFIG_MIPI_DSI
230 EXPORT_SYMBOL(dsi_enable_command_mode);
231 #endif
232 int dsi_enable_hs_clk(unsigned int id, u32 enable) {
233
234         struct mipi_dsi_ops *ops = NULL;
235
236         if(id > (MAX_DSI_CHIPS - 1))
237                 return -EINVAL;
238
239         ops = dsi_ops[id];
240
241         if(!ops)
242                 return -EINVAL;
243
244         if(ops->dsi_enable_hs_clk)
245                 ops->dsi_enable_hs_clk(ops->dsi, enable);
246
247         return 0;
248
249 }
250 #ifdef CONFIG_MIPI_DSI
251 EXPORT_SYMBOL(dsi_enable_hs_clk);
252 #endif
253 int dsi_is_active(unsigned int id) {
254
255         struct mipi_dsi_ops *ops = NULL;
256
257         if(id > (MAX_DSI_CHIPS - 1))
258                 return -EINVAL;
259
260         ops = dsi_ops[id];
261
262         if(!ops)
263                 return -EINVAL;
264
265         if(ops->dsi_is_active)
266                 return ops->dsi_is_active(ops->dsi);
267         else
268                 return -1;
269 }
270 #ifdef CONFIG_MIPI_DSI
271 EXPORT_SYMBOL(dsi_is_active);
272 #endif
273 int dsi_is_enable(unsigned int id, u32 enable){
274
275     struct mipi_dsi_ops *ops = NULL;
276
277         if(id > (MAX_DSI_CHIPS - 1))
278                 return -EINVAL;
279
280         ops = dsi_ops[id];
281
282         if(!ops)
283                 return -EINVAL;
284
285         if(ops->dsi_is_enable)
286                 ops->dsi_is_enable(ops->dsi, enable);
287
288         return 0;
289         
290 }
291 #ifdef CONFIG_MIPI_DSI
292 EXPORT_SYMBOL(dsi_is_enable);
293 #endif
294 int dsi_send_dcs_packet(unsigned int id, unsigned char *packet, u32 n) {
295
296         struct mipi_dsi_ops *ops = NULL;
297
298     //printk("dsi_send_dcs_packet-------id=%d\n",id);
299         if(id > (MAX_DSI_CHIPS - 1))
300                 return -EINVAL;
301
302         ops = dsi_ops[id];
303
304         if(!ops)
305                 return -EINVAL;
306
307         if(ops->dsi_send_dcs_packet)
308                 ops->dsi_send_dcs_packet(ops->dsi, packet, n);
309         return 0;
310 }
311 #ifdef CONFIG_MIPI_DSI
312 EXPORT_SYMBOL(dsi_send_dcs_packet);
313 #endif
314
315 int dsi_read_dcs_packet(unsigned int id, unsigned char *packet, u32 n) {
316
317         struct mipi_dsi_ops *ops = NULL;
318
319         if(id > (MAX_DSI_CHIPS - 1))
320                 return -EINVAL;
321
322         ops = dsi_ops[id];
323
324         if(!ops)
325                 return -EINVAL;
326
327         if(ops->dsi_read_dcs_packet)
328                 ops->dsi_read_dcs_packet(ops->dsi, packet, n);
329         return 0;
330 }
331 #ifdef CONFIG_MIPI_DSI
332 EXPORT_SYMBOL(dsi_read_dcs_packet);
333 #endif
334
335 int dsi_send_packet(unsigned int id, unsigned char *packet, u32 n) {
336
337         struct mipi_dsi_ops *ops = NULL;
338
339         if(id > (MAX_DSI_CHIPS - 1))
340                 return -EINVAL;
341
342         ops = dsi_ops[id];
343
344         if(!ops)
345                 return -EINVAL;
346
347         if(ops->dsi_send_packet)
348                 ops->dsi_send_packet(ops->dsi, packet, n);
349                 
350         return 0;
351 }
352 #ifdef CONFIG_MIPI_DSI
353 EXPORT_SYMBOL(dsi_send_packet);
354 #endif