rk31xx lvds: add pwr_on and pwr_off function
[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         int ret = 0;
96         struct mipi_dsi_ops *ops = NULL;
97
98         if(id > (MAX_DSI_CHIPS - 1))
99                 return -EINVAL;
100
101         ops = dsi_ops[id];
102         if(!ops)
103                 return -EINVAL;
104
105         id = ops->get_id(ops->dsi);
106         if(id == ops->id) {
107                 printk("load mipi dsi chip:%s id:%08x\n", ops->name, ops->id);
108                 printk("%s\n", MIPI_DSI_VERSION_AND_TIME);
109         } else {
110                 printk("mipi dsi chip is not found, read id:%08x, but %08x is correct\n", id, ops->id);
111                 ret = -1;
112         }
113
114         return ret;
115 }
116 #ifdef CONFIG_MIPI_DSI
117 EXPORT_SYMBOL(dsi_probe_current_chip);
118 #endif
119 int dsi_power_up(unsigned int id) {
120
121         struct mipi_dsi_ops *ops = NULL;
122
123         if(id > (MAX_DSI_CHIPS - 1))
124                 return -EINVAL;
125
126         ops = dsi_ops[id];
127
128         if(!ops)
129                 return -EINVAL;
130         if(ops->power_up)
131                 ops->power_up(ops->dsi);
132         return 0;
133 }
134 #ifdef CONFIG_MIPI_DSI
135 EXPORT_SYMBOL(dsi_power_up);
136 #endif
137
138 int dsi_power_off(unsigned int id) {
139
140         struct mipi_dsi_ops *ops = NULL;
141
142         if(id > (MAX_DSI_CHIPS - 1))
143                 return -EINVAL;
144
145         ops = dsi_ops[id];
146
147         if(!ops)
148                 return -EINVAL;
149
150         if(ops->power_down)
151                 ops->power_down(ops->dsi);
152
153         return 0;
154 }
155 #ifdef CONFIG_MIPI_DSI
156 EXPORT_SYMBOL(dsi_power_off);
157 #endif
158 int dsi_set_regs(unsigned int id, void *array, u32 n) {
159
160         struct mipi_dsi_ops *ops = NULL;
161
162         if(id > (MAX_DSI_CHIPS - 1))
163                 return -EINVAL;
164
165         ops = dsi_ops[id];
166
167         if(!ops)
168                 return -EINVAL;
169
170         if(ops->dsi_set_regs)
171                 ops->dsi_set_regs(ops->dsi, array, n);
172
173         return 0;
174 }
175 #ifdef CONFIG_MIPI_DSI
176 EXPORT_SYMBOL(dsi_set_regs);
177 #endif
178 int dsi_init(unsigned int id, u32 n) {
179
180         struct mipi_dsi_ops *ops = NULL;
181
182         if(id > (MAX_DSI_CHIPS - 1))
183                 return -EINVAL;
184
185         ops = dsi_ops[id];
186
187         if(!ops)
188                 return -EINVAL;
189
190         if(ops->dsi_init)
191                 ops->dsi_init(ops->dsi, n);
192
193         return 0;
194 }
195 #ifdef CONFIG_MIPI_DSI
196 EXPORT_SYMBOL(dsi_init);
197 #endif
198 int dsi_enable_video_mode(unsigned int id, u32 enable) {
199
200         struct mipi_dsi_ops *ops = NULL;
201
202         if(id > (MAX_DSI_CHIPS - 1))
203                 return -EINVAL;
204
205         ops = dsi_ops[id];
206
207         if(!ops)
208                 return -EINVAL;
209
210         if(ops->dsi_enable_video_mode)
211                 ops->dsi_enable_video_mode(ops->dsi, enable);
212
213         return 0;
214
215 }
216 #ifdef CONFIG_MIPI_DSI
217 EXPORT_SYMBOL(dsi_enable_video_mode);
218 #endif
219 int dsi_enable_command_mode(unsigned int id, u32 enable) {
220
221         struct mipi_dsi_ops *ops = NULL;
222
223         if(id > (MAX_DSI_CHIPS - 1))
224                 return -EINVAL;
225
226         ops = dsi_ops[id];
227
228         if(!ops)
229                 return -EINVAL;
230
231         if(ops->dsi_enable_command_mode)
232                 ops->dsi_enable_command_mode(ops->dsi, enable);
233
234         return 0;
235
236 }
237 #ifdef CONFIG_MIPI_DSI
238 EXPORT_SYMBOL(dsi_enable_command_mode);
239 #endif
240 int dsi_enable_hs_clk(unsigned int id, u32 enable) {
241
242         struct mipi_dsi_ops *ops = NULL;
243
244         if(id > (MAX_DSI_CHIPS - 1))
245                 return -EINVAL;
246
247         ops = dsi_ops[id];
248
249         if(!ops)
250                 return -EINVAL;
251
252         if(ops->dsi_enable_hs_clk)
253                 ops->dsi_enable_hs_clk(ops->dsi, enable);
254
255         return 0;
256
257 }
258 #ifdef CONFIG_MIPI_DSI
259 EXPORT_SYMBOL(dsi_enable_hs_clk);
260 #endif
261 int dsi_is_active(unsigned int id) {
262
263         struct mipi_dsi_ops *ops = NULL;
264
265         if(id > (MAX_DSI_CHIPS - 1))
266                 return -EINVAL;
267
268         ops = dsi_ops[id];
269
270         if(!ops)
271                 return -EINVAL;
272
273         if(ops->dsi_is_active)
274                 return ops->dsi_is_active(ops->dsi);
275         else
276                 return -1;
277 }
278 #ifdef CONFIG_MIPI_DSI
279 EXPORT_SYMBOL(dsi_is_active);
280 #endif
281 int dsi_is_enable(unsigned int id, u32 enable){
282
283     struct mipi_dsi_ops *ops = NULL;
284
285         if(id > (MAX_DSI_CHIPS - 1))
286                 return -EINVAL;
287
288         ops = dsi_ops[id];
289
290         if(!ops)
291                 return -EINVAL;
292
293         if(ops->dsi_is_enable)
294                 ops->dsi_is_enable(ops->dsi, enable);
295
296         return 0;
297         
298 }
299 #ifdef CONFIG_MIPI_DSI
300 EXPORT_SYMBOL(dsi_is_enable);
301 #endif
302 int dsi_send_dcs_packet(unsigned int id, unsigned char *packet, u32 n) {
303
304         struct mipi_dsi_ops *ops = NULL;
305
306     //printk("dsi_send_dcs_packet-------id=%d\n",id);
307         if(id > (MAX_DSI_CHIPS - 1))
308                 return -EINVAL;
309
310         ops = dsi_ops[id];
311
312         if(!ops)
313                 return -EINVAL;
314
315         if(ops->dsi_send_dcs_packet)
316                 ops->dsi_send_dcs_packet(ops->dsi, packet, n);
317         return 0;
318 }
319 #ifdef CONFIG_MIPI_DSI
320 EXPORT_SYMBOL(dsi_send_dcs_packet);
321 #endif
322
323 int dsi_read_dcs_packet(unsigned int id, unsigned char *packet, u32 n) {
324
325         struct mipi_dsi_ops *ops = NULL;
326
327         if(id > (MAX_DSI_CHIPS - 1))
328                 return -EINVAL;
329
330         ops = dsi_ops[id];
331
332         if(!ops)
333                 return -EINVAL;
334
335         if(ops->dsi_read_dcs_packet)
336                 ops->dsi_read_dcs_packet(ops->dsi, packet, n);
337         return 0;
338 }
339 #ifdef CONFIG_MIPI_DSI
340 EXPORT_SYMBOL(dsi_read_dcs_packet);
341 #endif
342
343 int dsi_send_packet(unsigned int id, unsigned char *packet, u32 n) {
344
345         struct mipi_dsi_ops *ops = NULL;
346
347         if(id > (MAX_DSI_CHIPS - 1))
348                 return -EINVAL;
349
350         ops = dsi_ops[id];
351
352         if(!ops)
353                 return -EINVAL;
354
355         if(ops->dsi_send_packet)
356                 ops->dsi_send_packet(ops->dsi, packet, n);
357                 
358         return 0;
359 }
360 #ifdef CONFIG_MIPI_DSI
361 EXPORT_SYMBOL(dsi_send_packet);
362 #endif