mmp_disp.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. * pitch[0]: graphics/video layer line length or y pitch
  92. * pitch[1]/pitch[2]: video u/v pitch if non-zero
  93. */
  94. u32 pitch[3];
  95. };
  96. struct mmp_addr {
  97. /* phys address */
  98. u32 phys[6];
  99. };
  100. /* path related para: mode */
  101. struct mmp_mode {
  102. const char *name;
  103. u32 refresh;
  104. u32 xres;
  105. u32 yres;
  106. u32 left_margin;
  107. u32 right_margin;
  108. u32 upper_margin;
  109. u32 lower_margin;
  110. u32 hsync_len;
  111. u32 vsync_len;
  112. u32 hsync_invert;
  113. u32 vsync_invert;
  114. u32 invert_pixclock;
  115. u32 pixclock_freq;
  116. int pix_fmt_out;
  117. };
  118. /* main structures */
  119. struct mmp_path;
  120. struct mmp_overlay;
  121. struct mmp_panel;
  122. /* status types */
  123. enum {
  124. MMP_OFF = 0,
  125. MMP_ON,
  126. };
  127. static inline const char *stat_name(int stat)
  128. {
  129. switch (stat) {
  130. case MMP_OFF:
  131. return "OFF";
  132. case MMP_ON:
  133. return "ON";
  134. default:
  135. return "UNKNOWNSTAT";
  136. }
  137. }
  138. struct mmp_overlay_ops {
  139. /* should be provided by driver */
  140. void (*set_fetch)(struct mmp_overlay *overlay, int fetch_id);
  141. void (*set_onoff)(struct mmp_overlay *overlay, int status);
  142. void (*set_win)(struct mmp_overlay *overlay, struct mmp_win *win);
  143. int (*set_addr)(struct mmp_overlay *overlay, struct mmp_addr *addr);
  144. };
  145. /* overlay describes a z-order indexed slot in each path. */
  146. struct mmp_overlay {
  147. int id;
  148. const char *name;
  149. struct mmp_path *path;
  150. /* overlay info: private data */
  151. int dmafetch_id;
  152. struct mmp_addr addr;
  153. struct mmp_win win;
  154. /* state */
  155. int open_count;
  156. int status;
  157. struct mutex access_ok;
  158. struct mmp_overlay_ops *ops;
  159. };
  160. /* panel type */
  161. enum {
  162. PANELTYPE_ACTIVE = 0,
  163. PANELTYPE_SMART,
  164. PANELTYPE_TV,
  165. PANELTYPE_DSI_CMD,
  166. PANELTYPE_DSI_VIDEO,
  167. };
  168. struct mmp_panel {
  169. /* use node to register to list */
  170. struct list_head node;
  171. const char *name;
  172. /* path name used to connect to proper path configed */
  173. const char *plat_path_name;
  174. struct device *dev;
  175. int panel_type;
  176. void *plat_data;
  177. int (*get_modelist)(struct mmp_panel *panel,
  178. struct mmp_mode **modelist);
  179. void (*set_mode)(struct mmp_panel *panel,
  180. struct mmp_mode *mode);
  181. void (*set_onoff)(struct mmp_panel *panel,
  182. int status);
  183. };
  184. struct mmp_path_ops {
  185. int (*check_status)(struct mmp_path *path);
  186. struct mmp_overlay *(*get_overlay)(struct mmp_path *path,
  187. int overlay_id);
  188. int (*get_modelist)(struct mmp_path *path,
  189. struct mmp_mode **modelist);
  190. /* follow ops should be provided by driver */
  191. void (*set_mode)(struct mmp_path *path, struct mmp_mode *mode);
  192. void (*set_onoff)(struct mmp_path *path, int status);
  193. /* todo: add query */
  194. };
  195. /* path output types */
  196. enum {
  197. PATH_OUT_PARALLEL,
  198. PATH_OUT_DSI,
  199. PATH_OUT_HDMI,
  200. };
  201. /* path is main part of mmp-disp */
  202. struct mmp_path {
  203. /* use node to register to list */
  204. struct list_head node;
  205. /* init data */
  206. struct device *dev;
  207. int id;
  208. const char *name;
  209. int output_type;
  210. struct mmp_panel *panel;
  211. void *plat_data;
  212. /* dynamic use */
  213. struct mmp_mode mode;
  214. /* state */
  215. int open_count;
  216. int status;
  217. struct mutex access_ok;
  218. struct mmp_path_ops ops;
  219. /* layers */
  220. int overlay_num;
  221. struct mmp_overlay overlays[0];
  222. };
  223. extern struct mmp_path *mmp_get_path(const char *name);
  224. static inline void mmp_path_set_mode(struct mmp_path *path,
  225. struct mmp_mode *mode)
  226. {
  227. if (path)
  228. path->ops.set_mode(path, mode);
  229. }
  230. static inline void mmp_path_set_onoff(struct mmp_path *path, int status)
  231. {
  232. if (path)
  233. path->ops.set_onoff(path, status);
  234. }
  235. static inline int mmp_path_get_modelist(struct mmp_path *path,
  236. struct mmp_mode **modelist)
  237. {
  238. if (path)
  239. return path->ops.get_modelist(path, modelist);
  240. return 0;
  241. }
  242. static inline struct mmp_overlay *mmp_path_get_overlay(
  243. struct mmp_path *path, int overlay_id)
  244. {
  245. if (path)
  246. return path->ops.get_overlay(path, overlay_id);
  247. return NULL;
  248. }
  249. static inline void mmp_overlay_set_fetch(struct mmp_overlay *overlay,
  250. int fetch_id)
  251. {
  252. if (overlay)
  253. overlay->ops->set_fetch(overlay, fetch_id);
  254. }
  255. static inline void mmp_overlay_set_onoff(struct mmp_overlay *overlay,
  256. int status)
  257. {
  258. if (overlay)
  259. overlay->ops->set_onoff(overlay, status);
  260. }
  261. static inline void mmp_overlay_set_win(struct mmp_overlay *overlay,
  262. struct mmp_win *win)
  263. {
  264. if (overlay)
  265. overlay->ops->set_win(overlay, win);
  266. }
  267. static inline int mmp_overlay_set_addr(struct mmp_overlay *overlay,
  268. struct mmp_addr *addr)
  269. {
  270. if (overlay)
  271. return overlay->ops->set_addr(overlay, addr);
  272. return 0;
  273. }
  274. /*
  275. * driver data is set from each detailed ctrl driver for path usage
  276. * it defined a common interface that plat driver need to implement
  277. */
  278. struct mmp_path_info {
  279. /* driver data, set when registed*/
  280. const char *name;
  281. struct device *dev;
  282. int id;
  283. int output_type;
  284. int overlay_num;
  285. void (*set_mode)(struct mmp_path *path, struct mmp_mode *mode);
  286. void (*set_onoff)(struct mmp_path *path, int status);
  287. struct mmp_overlay_ops *overlay_ops;
  288. void *plat_data;
  289. };
  290. extern struct mmp_path *mmp_register_path(
  291. struct mmp_path_info *info);
  292. extern void mmp_unregister_path(struct mmp_path *path);
  293. extern void mmp_register_panel(struct mmp_panel *panel);
  294. extern void mmp_unregister_panel(struct mmp_panel *panel);
  295. /* defintions for platform data */
  296. /* interface for buffer driver */
  297. struct mmp_buffer_driver_mach_info {
  298. const char *name;
  299. const char *path_name;
  300. int overlay_id;
  301. int dmafetch_id;
  302. int default_pixfmt;
  303. };
  304. /* interface for controllers driver */
  305. struct mmp_mach_path_config {
  306. const char *name;
  307. int overlay_num;
  308. int output_type;
  309. u32 path_config;
  310. u32 link_config;
  311. u32 dsi_rbswap;
  312. };
  313. struct mmp_mach_plat_info {
  314. const char *name;
  315. const char *clk_name;
  316. int path_num;
  317. struct mmp_mach_path_config *paths;
  318. };
  319. /* interface for panel drivers */
  320. struct mmp_mach_panel_info {
  321. const char *name;
  322. void (*plat_set_onoff)(int status);
  323. const char *plat_path_name;
  324. };
  325. #endif /* _MMP_DISP_H_ */