mmp_disp.h 7.0 KB

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