mmp_disp.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. #ifndef _MMP_DISP_H_
  23. #define _MMP_DISP_H_
  24. #include <linux/kthread.h>
  25. enum {
  26. PIXFMT_UYVY = 0,
  27. PIXFMT_VYUY,
  28. PIXFMT_YUYV,
  29. PIXFMT_YUV422P,
  30. PIXFMT_YVU422P,
  31. PIXFMT_YUV420P,
  32. PIXFMT_YVU420P,
  33. PIXFMT_RGB565 = 0x100,
  34. PIXFMT_BGR565,
  35. PIXFMT_RGB1555,
  36. PIXFMT_BGR1555,
  37. PIXFMT_RGB888PACK,
  38. PIXFMT_BGR888PACK,
  39. PIXFMT_RGB888UNPACK,
  40. PIXFMT_BGR888UNPACK,
  41. PIXFMT_RGBA888,
  42. PIXFMT_BGRA888,
  43. PIXFMT_RGB666, /* for output usage */
  44. PIXFMT_PSEUDOCOLOR = 0x200,
  45. };
  46. static inline int pixfmt_to_stride(int pix_fmt)
  47. {
  48. switch (pix_fmt) {
  49. case PIXFMT_RGB565:
  50. case PIXFMT_BGR565:
  51. case PIXFMT_RGB1555:
  52. case PIXFMT_BGR1555:
  53. case PIXFMT_UYVY:
  54. case PIXFMT_VYUY:
  55. case PIXFMT_YUYV:
  56. return 2;
  57. case PIXFMT_RGB888UNPACK:
  58. case PIXFMT_BGR888UNPACK:
  59. case PIXFMT_RGBA888:
  60. case PIXFMT_BGRA888:
  61. return 4;
  62. case PIXFMT_RGB888PACK:
  63. case PIXFMT_BGR888PACK:
  64. return 3;
  65. case PIXFMT_YUV422P:
  66. case PIXFMT_YVU422P:
  67. case PIXFMT_YUV420P:
  68. case PIXFMT_YVU420P:
  69. case PIXFMT_PSEUDOCOLOR:
  70. return 1;
  71. default:
  72. return 0;
  73. }
  74. }
  75. /* parameters used by path/overlay */
  76. /* overlay related para: win/addr */
  77. struct mmp_win {
  78. /* position/size of window */
  79. u16 xsrc;
  80. u16 ysrc;
  81. u16 xdst;
  82. u16 ydst;
  83. u16 xpos;
  84. u16 ypos;
  85. u16 left_crop;
  86. u16 right_crop;
  87. u16 up_crop;
  88. u16 bottom_crop;
  89. int pix_fmt;
  90. };
  91. struct mmp_addr {
  92. /* phys address */
  93. u32 phys[6];
  94. };
  95. /* path related para: mode */
  96. struct mmp_mode {
  97. const char *name;
  98. u32 refresh;
  99. u32 xres;
  100. u32 yres;
  101. u32 left_margin;
  102. u32 right_margin;
  103. u32 upper_margin;
  104. u32 lower_margin;
  105. u32 hsync_len;
  106. u32 vsync_len;
  107. u32 hsync_invert;
  108. u32 vsync_invert;
  109. u32 invert_pixclock;
  110. u32 pixclock_freq;
  111. int pix_fmt_out;
  112. };
  113. /* main structures */
  114. struct mmp_path;
  115. struct mmp_overlay;
  116. struct mmp_panel;
  117. /* status types */
  118. enum {
  119. MMP_OFF = 0,
  120. MMP_ON,
  121. };
  122. static inline const char *stat_name(int stat)
  123. {
  124. switch (stat) {
  125. case MMP_OFF:
  126. return "OFF";
  127. case MMP_ON:
  128. return "ON";
  129. default:
  130. return "UNKNOWNSTAT";
  131. }
  132. }
  133. struct mmp_overlay_ops {
  134. /* should be provided by driver */
  135. void (*set_fetch)(struct mmp_overlay *overlay, int fetch_id);
  136. void (*set_onoff)(struct mmp_overlay *overlay, int status);
  137. void (*set_win)(struct mmp_overlay *overlay, struct mmp_win *win);
  138. int (*set_addr)(struct mmp_overlay *overlay, struct mmp_addr *addr);
  139. };
  140. /* overlay describes a z-order indexed slot in each path. */
  141. struct mmp_overlay {
  142. int id;
  143. const char *name;
  144. struct mmp_path *path;
  145. /* overlay info: private data */
  146. int dmafetch_id;
  147. struct mmp_addr addr;
  148. struct mmp_win win;
  149. /* state */
  150. int open_count;
  151. int status;
  152. struct mutex access_ok;
  153. struct mmp_overlay_ops *ops;
  154. };
  155. /* panel type */
  156. enum {
  157. PANELTYPE_ACTIVE = 0,
  158. PANELTYPE_SMART,
  159. PANELTYPE_TV,
  160. PANELTYPE_DSI_CMD,
  161. PANELTYPE_DSI_VIDEO,
  162. };
  163. struct mmp_panel {
  164. /* use node to register to list */
  165. struct list_head node;
  166. const char *name;
  167. /* path name used to connect to proper path configed */
  168. const char *plat_path_name;
  169. struct device *dev;
  170. int panel_type;
  171. void *plat_data;
  172. int (*get_modelist)(struct mmp_panel *panel,
  173. struct mmp_mode **modelist);
  174. void (*set_mode)(struct mmp_panel *panel,
  175. struct mmp_mode *mode);
  176. void (*set_onoff)(struct mmp_panel *panel,
  177. int status);
  178. };
  179. struct mmp_path_ops {
  180. int (*check_status)(struct mmp_path *path);
  181. struct mmp_overlay *(*get_overlay)(struct mmp_path *path,
  182. int overlay_id);
  183. int (*get_modelist)(struct mmp_path *path,
  184. struct mmp_mode **modelist);
  185. /* follow ops should be provided by driver */
  186. void (*set_mode)(struct mmp_path *path, struct mmp_mode *mode);
  187. void (*set_onoff)(struct mmp_path *path, int status);
  188. /* todo: add query */
  189. };
  190. /* path output types */
  191. enum {
  192. PATH_OUT_PARALLEL,
  193. PATH_OUT_DSI,
  194. PATH_OUT_HDMI,
  195. };
  196. /* path is main part of mmp-disp */
  197. struct mmp_path {
  198. /* use node to register to list */
  199. struct list_head node;
  200. /* init data */
  201. struct device *dev;
  202. int id;
  203. const char *name;
  204. int output_type;
  205. struct mmp_panel *panel;
  206. void *plat_data;
  207. /* dynamic use */
  208. struct mmp_mode mode;
  209. /* state */
  210. int open_count;
  211. int status;
  212. struct mutex access_ok;
  213. struct mmp_path_ops ops;
  214. /* layers */
  215. int overlay_num;
  216. struct mmp_overlay overlays[0];
  217. };
  218. extern struct mmp_path *mmp_get_path(const char *name);
  219. static inline void mmp_path_set_mode(struct mmp_path *path,
  220. struct mmp_mode *mode)
  221. {
  222. if (path)
  223. path->ops.set_mode(path, mode);
  224. }
  225. static inline void mmp_path_set_onoff(struct mmp_path *path, int status)
  226. {
  227. if (path)
  228. path->ops.set_onoff(path, status);
  229. }
  230. static inline int mmp_path_get_modelist(struct mmp_path *path,
  231. struct mmp_mode **modelist)
  232. {
  233. if (path)
  234. return path->ops.get_modelist(path, modelist);
  235. return 0;
  236. }
  237. static inline struct mmp_overlay *mmp_path_get_overlay(
  238. struct mmp_path *path, int overlay_id)
  239. {
  240. if (path)
  241. return path->ops.get_overlay(path, overlay_id);
  242. return NULL;
  243. }
  244. static inline void mmp_overlay_set_fetch(struct mmp_overlay *overlay,
  245. int fetch_id)
  246. {
  247. if (overlay)
  248. overlay->ops->set_fetch(overlay, fetch_id);
  249. }
  250. static inline void mmp_overlay_set_onoff(struct mmp_overlay *overlay,
  251. int status)
  252. {
  253. if (overlay)
  254. overlay->ops->set_onoff(overlay, status);
  255. }
  256. static inline void mmp_overlay_set_win(struct mmp_overlay *overlay,
  257. struct mmp_win *win)
  258. {
  259. if (overlay)
  260. overlay->ops->set_win(overlay, win);
  261. }
  262. static inline int mmp_overlay_set_addr(struct mmp_overlay *overlay,
  263. struct mmp_addr *addr)
  264. {
  265. if (overlay)
  266. return overlay->ops->set_addr(overlay, addr);
  267. return 0;
  268. }
  269. /*
  270. * driver data is set from each detailed ctrl driver for path usage
  271. * it defined a common interface that plat driver need to implement
  272. */
  273. struct mmp_path_info {
  274. /* driver data, set when registed*/
  275. const char *name;
  276. struct device *dev;
  277. int id;
  278. int output_type;
  279. int overlay_num;
  280. void (*set_mode)(struct mmp_path *path, struct mmp_mode *mode);
  281. void (*set_onoff)(struct mmp_path *path, int status);
  282. struct mmp_overlay_ops *overlay_ops;
  283. void *plat_data;
  284. };
  285. extern struct mmp_path *mmp_register_path(
  286. struct mmp_path_info *info);
  287. extern void mmp_unregister_path(struct mmp_path *path);
  288. extern void mmp_register_panel(struct mmp_panel *panel);
  289. extern void mmp_unregister_panel(struct mmp_panel *panel);
  290. /* defintions for platform data */
  291. /* interface for buffer driver */
  292. struct mmp_buffer_driver_mach_info {
  293. const char *name;
  294. const char *path_name;
  295. int overlay_id;
  296. int dmafetch_id;
  297. int default_pixfmt;
  298. };
  299. /* interface for controllers driver */
  300. struct mmp_mach_path_config {
  301. const char *name;
  302. int overlay_num;
  303. int output_type;
  304. u32 path_config;
  305. u32 link_config;
  306. };
  307. struct mmp_mach_plat_info {
  308. const char *name;
  309. const char *clk_name;
  310. int path_num;
  311. struct mmp_mach_path_config *paths;
  312. };
  313. /* interface for panel drivers */
  314. struct mmp_mach_panel_info {
  315. const char *name;
  316. void (*plat_set_onoff)(int status);
  317. const char *plat_path_name;
  318. };
  319. #endif /* _MMP_DISP_H_ */