Merge tag 'v3.10.60' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / video / mmp_disp.h
CommitLineData
59393bb9
ZZ
1/*
2 * linux/include/video/mmp_disp.h
3 * Header file for Marvell MMP Display Controller
4 *
5 * Copyright (C) 2012 Marvell Technology Group Ltd.
6 * Authors: Zhou Zhu <zzhu3@marvell.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef _MMP_DISP_H_
24#define _MMP_DISP_H_
25#include <linux/kthread.h>
26
27enum {
28 PIXFMT_UYVY = 0,
29 PIXFMT_VYUY,
30 PIXFMT_YUYV,
31 PIXFMT_YUV422P,
32 PIXFMT_YVU422P,
33 PIXFMT_YUV420P,
34 PIXFMT_YVU420P,
35 PIXFMT_RGB565 = 0x100,
36 PIXFMT_BGR565,
37 PIXFMT_RGB1555,
38 PIXFMT_BGR1555,
39 PIXFMT_RGB888PACK,
40 PIXFMT_BGR888PACK,
41 PIXFMT_RGB888UNPACK,
42 PIXFMT_BGR888UNPACK,
43 PIXFMT_RGBA888,
44 PIXFMT_BGRA888,
45 PIXFMT_RGB666, /* for output usage */
46 PIXFMT_PSEUDOCOLOR = 0x200,
47};
48
49static inline int pixfmt_to_stride(int pix_fmt)
50{
51 switch (pix_fmt) {
52 case PIXFMT_RGB565:
53 case PIXFMT_BGR565:
54 case PIXFMT_RGB1555:
55 case PIXFMT_BGR1555:
56 case PIXFMT_UYVY:
57 case PIXFMT_VYUY:
58 case PIXFMT_YUYV:
59 return 2;
60 case PIXFMT_RGB888UNPACK:
61 case PIXFMT_BGR888UNPACK:
62 case PIXFMT_RGBA888:
63 case PIXFMT_BGRA888:
64 return 4;
65 case PIXFMT_RGB888PACK:
66 case PIXFMT_BGR888PACK:
67 return 3;
68 case PIXFMT_YUV422P:
69 case PIXFMT_YVU422P:
70 case PIXFMT_YUV420P:
71 case PIXFMT_YVU420P:
72 case PIXFMT_PSEUDOCOLOR:
73 return 1;
74 default:
75 return 0;
76 }
77}
78
79/* parameters used by path/overlay */
80/* overlay related para: win/addr */
81struct mmp_win {
82 /* position/size of window */
83 u16 xsrc;
84 u16 ysrc;
85 u16 xdst;
86 u16 ydst;
87 u16 xpos;
88 u16 ypos;
89 u16 left_crop;
90 u16 right_crop;
91 u16 up_crop;
92 u16 bottom_crop;
93 int pix_fmt;
94};
95
96struct mmp_addr {
97 /* phys address */
98 u32 phys[6];
99};
100
101/* path related para: mode */
102struct mmp_mode {
103 const char *name;
104 u32 refresh;
105 u32 xres;
106 u32 yres;
107 u32 left_margin;
108 u32 right_margin;
109 u32 upper_margin;
110 u32 lower_margin;
111 u32 hsync_len;
112 u32 vsync_len;
113 u32 hsync_invert;
114 u32 vsync_invert;
115 u32 invert_pixclock;
116 u32 pixclock_freq;
117 int pix_fmt_out;
118};
119
120/* main structures */
121struct mmp_path;
122struct mmp_overlay;
123struct mmp_panel;
124
125/* status types */
126enum {
127 MMP_OFF = 0,
128 MMP_ON,
129};
130
131static inline const char *stat_name(int stat)
132{
133 switch (stat) {
134 case MMP_OFF:
135 return "OFF";
136 case MMP_ON:
137 return "ON";
138 default:
139 return "UNKNOWNSTAT";
140 }
141}
142
143struct mmp_overlay_ops {
144 /* should be provided by driver */
145 void (*set_fetch)(struct mmp_overlay *overlay, int fetch_id);
146 void (*set_onoff)(struct mmp_overlay *overlay, int status);
147 void (*set_win)(struct mmp_overlay *overlay, struct mmp_win *win);
148 int (*set_addr)(struct mmp_overlay *overlay, struct mmp_addr *addr);
149};
150
151/* overlay describes a z-order indexed slot in each path. */
152struct mmp_overlay {
153 int id;
154 const char *name;
155 struct mmp_path *path;
156
157 /* overlay info: private data */
158 int dmafetch_id;
159 struct mmp_addr addr;
160 struct mmp_win win;
161
162 /* state */
163 int open_count;
164 int status;
165 struct mutex access_ok;
166
167 struct mmp_overlay_ops *ops;
168};
169
170/* panel type */
171enum {
172 PANELTYPE_ACTIVE = 0,
173 PANELTYPE_SMART,
174 PANELTYPE_TV,
175 PANELTYPE_DSI_CMD,
176 PANELTYPE_DSI_VIDEO,
177};
178
179struct mmp_panel {
180 /* use node to register to list */
181 struct list_head node;
182 const char *name;
183 /* path name used to connect to proper path configed */
184 const char *plat_path_name;
185 struct device *dev;
186 int panel_type;
187 void *plat_data;
188 int (*get_modelist)(struct mmp_panel *panel,
189 struct mmp_mode **modelist);
190 void (*set_mode)(struct mmp_panel *panel,
191 struct mmp_mode *mode);
192 void (*set_onoff)(struct mmp_panel *panel,
193 int status);
194};
195
196struct mmp_path_ops {
197 int (*check_status)(struct mmp_path *path);
198 struct mmp_overlay *(*get_overlay)(struct mmp_path *path,
199 int overlay_id);
200 int (*get_modelist)(struct mmp_path *path,
201 struct mmp_mode **modelist);
202
203 /* follow ops should be provided by driver */
204 void (*set_mode)(struct mmp_path *path, struct mmp_mode *mode);
205 void (*set_onoff)(struct mmp_path *path, int status);
206 /* todo: add query */
207};
208
209/* path output types */
210enum {
211 PATH_OUT_PARALLEL,
212 PATH_OUT_DSI,
213 PATH_OUT_HDMI,
214};
215
216/* path is main part of mmp-disp */
217struct mmp_path {
218 /* use node to register to list */
219 struct list_head node;
220
221 /* init data */
222 struct device *dev;
223
224 int id;
225 const char *name;
226 int output_type;
227 struct mmp_panel *panel;
228 void *plat_data;
229
230 /* dynamic use */
231 struct mmp_mode mode;
232
233 /* state */
234 int open_count;
235 int status;
236 struct mutex access_ok;
237
238 struct mmp_path_ops ops;
239
240 /* layers */
241 int overlay_num;
242 struct mmp_overlay overlays[0];
243};
244
245extern struct mmp_path *mmp_get_path(const char *name);
246static inline void mmp_path_set_mode(struct mmp_path *path,
247 struct mmp_mode *mode)
248{
249 if (path)
250 path->ops.set_mode(path, mode);
251}
252static inline void mmp_path_set_onoff(struct mmp_path *path, int status)
253{
254 if (path)
255 path->ops.set_onoff(path, status);
256}
257static inline int mmp_path_get_modelist(struct mmp_path *path,
258 struct mmp_mode **modelist)
259{
260 if (path)
261 return path->ops.get_modelist(path, modelist);
262 return 0;
263}
264static inline struct mmp_overlay *mmp_path_get_overlay(
265 struct mmp_path *path, int overlay_id)
266{
267 if (path)
268 return path->ops.get_overlay(path, overlay_id);
269 return NULL;
270}
271static inline void mmp_overlay_set_fetch(struct mmp_overlay *overlay,
272 int fetch_id)
273{
274 if (overlay)
275 overlay->ops->set_fetch(overlay, fetch_id);
276}
277static inline void mmp_overlay_set_onoff(struct mmp_overlay *overlay,
278 int status)
279{
280 if (overlay)
281 overlay->ops->set_onoff(overlay, status);
282}
283static inline void mmp_overlay_set_win(struct mmp_overlay *overlay,
284 struct mmp_win *win)
285{
286 if (overlay)
287 overlay->ops->set_win(overlay, win);
288}
289static inline int mmp_overlay_set_addr(struct mmp_overlay *overlay,
290 struct mmp_addr *addr)
291{
292 if (overlay)
293 return overlay->ops->set_addr(overlay, addr);
294 return 0;
295}
296
297/*
298 * driver data is set from each detailed ctrl driver for path usage
299 * it defined a common interface that plat driver need to implement
300 */
301struct mmp_path_info {
302 /* driver data, set when registed*/
303 const char *name;
304 struct device *dev;
305 int id;
306 int output_type;
307 int overlay_num;
308 void (*set_mode)(struct mmp_path *path, struct mmp_mode *mode);
309 void (*set_onoff)(struct mmp_path *path, int status);
310 struct mmp_overlay_ops *overlay_ops;
311 void *plat_data;
312};
313
314extern struct mmp_path *mmp_register_path(
315 struct mmp_path_info *info);
316extern void mmp_unregister_path(struct mmp_path *path);
317extern void mmp_register_panel(struct mmp_panel *panel);
318extern void mmp_unregister_panel(struct mmp_panel *panel);
319
320/* defintions for platform data */
321/* interface for buffer driver */
322struct mmp_buffer_driver_mach_info {
323 const char *name;
324 const char *path_name;
325 int overlay_id;
326 int dmafetch_id;
327 int default_pixfmt;
328};
329
330/* interface for controllers driver */
331struct mmp_mach_path_config {
332 const char *name;
333 int overlay_num;
334 int output_type;
335 u32 path_config;
336 u32 link_config;
337};
338
339struct mmp_mach_plat_info {
340 const char *name;
341 const char *clk_name;
342 int path_num;
343 struct mmp_mach_path_config *paths;
344};
345
346/* interface for panel drivers */
347struct mmp_mach_panel_info {
348 const char *name;
349 void (*plat_set_onoff)(int status);
350 const char *plat_path_name;
351};
352#endif /* _MMP_DISP_H_ */