exynos_drm_drv.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /* exynos_drm_drv.h
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * Authors:
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. * Seung-Woo Kim <sw0312.kim@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #ifndef _EXYNOS_DRM_DRV_H_
  15. #define _EXYNOS_DRM_DRV_H_
  16. #include <linux/module.h>
  17. #define MAX_CRTC 3
  18. #define MAX_PLANE 5
  19. #define MAX_FB_BUFFER 4
  20. #define DEFAULT_ZPOS -1
  21. #define _wait_for(COND, MS) ({ \
  22. unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
  23. int ret__ = 0; \
  24. while (!(COND)) { \
  25. if (time_after(jiffies, timeout__)) { \
  26. ret__ = -ETIMEDOUT; \
  27. break; \
  28. } \
  29. } \
  30. ret__; \
  31. })
  32. #define wait_for(COND, MS) _wait_for(COND, MS)
  33. struct drm_device;
  34. struct exynos_drm_overlay;
  35. struct drm_connector;
  36. extern unsigned int drm_vblank_offdelay;
  37. /* This enumerates device type. */
  38. enum exynos_drm_device_type {
  39. EXYNOS_DEVICE_TYPE_NONE,
  40. EXYNOS_DEVICE_TYPE_CRTC,
  41. EXYNOS_DEVICE_TYPE_CONNECTOR,
  42. };
  43. /* this enumerates display type. */
  44. enum exynos_drm_output_type {
  45. EXYNOS_DISPLAY_TYPE_NONE,
  46. /* RGB or CPU Interface. */
  47. EXYNOS_DISPLAY_TYPE_LCD,
  48. /* HDMI Interface. */
  49. EXYNOS_DISPLAY_TYPE_HDMI,
  50. /* Virtual Display Interface. */
  51. EXYNOS_DISPLAY_TYPE_VIDI,
  52. };
  53. /*
  54. * Exynos drm common overlay structure.
  55. *
  56. * @fb_x: offset x on a framebuffer to be displayed.
  57. * - the unit is screen coordinates.
  58. * @fb_y: offset y on a framebuffer to be displayed.
  59. * - the unit is screen coordinates.
  60. * @fb_width: width of a framebuffer.
  61. * @fb_height: height of a framebuffer.
  62. * @src_width: width of a partial image to be displayed from framebuffer.
  63. * @src_height: height of a partial image to be displayed from framebuffer.
  64. * @crtc_x: offset x on hardware screen.
  65. * @crtc_y: offset y on hardware screen.
  66. * @crtc_width: window width to be displayed (hardware screen).
  67. * @crtc_height: window height to be displayed (hardware screen).
  68. * @mode_width: width of screen mode.
  69. * @mode_height: height of screen mode.
  70. * @refresh: refresh rate.
  71. * @scan_flag: interlace or progressive way.
  72. * (it could be DRM_MODE_FLAG_*)
  73. * @bpp: pixel size.(in bit)
  74. * @pixel_format: fourcc pixel format of this overlay
  75. * @dma_addr: array of bus(accessed by dma) address to the memory region
  76. * allocated for a overlay.
  77. * @zpos: order of overlay layer(z position).
  78. * @default_win: a window to be enabled.
  79. * @color_key: color key on or off.
  80. * @index_color: if using color key feature then this value would be used
  81. * as index color.
  82. * @local_path: in case of lcd type, local path mode on or off.
  83. * @transparency: transparency on or off.
  84. * @activated: activated or not.
  85. *
  86. * this structure is common to exynos SoC and its contents would be copied
  87. * to hardware specific overlay info.
  88. */
  89. struct exynos_drm_overlay {
  90. unsigned int fb_x;
  91. unsigned int fb_y;
  92. unsigned int fb_width;
  93. unsigned int fb_height;
  94. unsigned int src_width;
  95. unsigned int src_height;
  96. unsigned int crtc_x;
  97. unsigned int crtc_y;
  98. unsigned int crtc_width;
  99. unsigned int crtc_height;
  100. unsigned int mode_width;
  101. unsigned int mode_height;
  102. unsigned int refresh;
  103. unsigned int scan_flag;
  104. unsigned int bpp;
  105. unsigned int pitch;
  106. uint32_t pixel_format;
  107. dma_addr_t dma_addr[MAX_FB_BUFFER];
  108. int zpos;
  109. bool default_win;
  110. bool color_key;
  111. unsigned int index_color;
  112. bool local_path;
  113. bool transparency;
  114. bool activated;
  115. };
  116. /*
  117. * Exynos DRM Display Structure.
  118. * - this structure is common to analog tv, digital tv and lcd panel.
  119. *
  120. * @remove: cleans up the display for removal
  121. * @mode_fixup: fix mode data comparing to hw specific display mode.
  122. * @mode_set: convert drm_display_mode to hw specific display mode and
  123. * would be called by encoder->mode_set().
  124. * @check_mode: check if mode is valid or not.
  125. * @dpms: display device on or off.
  126. * @commit: apply changes to hw
  127. */
  128. struct exynos_drm_display;
  129. struct exynos_drm_display_ops {
  130. int (*create_connector)(struct exynos_drm_display *display,
  131. struct drm_encoder *encoder);
  132. void (*remove)(struct exynos_drm_display *display);
  133. void (*mode_fixup)(struct exynos_drm_display *display,
  134. struct drm_connector *connector,
  135. const struct drm_display_mode *mode,
  136. struct drm_display_mode *adjusted_mode);
  137. void (*mode_set)(struct exynos_drm_display *display,
  138. struct drm_display_mode *mode);
  139. int (*check_mode)(struct exynos_drm_display *display,
  140. struct drm_display_mode *mode);
  141. void (*dpms)(struct exynos_drm_display *display, int mode);
  142. void (*commit)(struct exynos_drm_display *display);
  143. };
  144. /*
  145. * Exynos drm display structure, maps 1:1 with an encoder/connector
  146. *
  147. * @list: the list entry for this manager
  148. * @type: one of EXYNOS_DISPLAY_TYPE_LCD and HDMI.
  149. * @encoder: encoder object this display maps to
  150. * @connector: connector object this display maps to
  151. * @ops: pointer to callbacks for exynos drm specific functionality
  152. * @ctx: A pointer to the display's implementation specific context
  153. */
  154. struct exynos_drm_display {
  155. struct list_head list;
  156. enum exynos_drm_output_type type;
  157. struct drm_encoder *encoder;
  158. struct drm_connector *connector;
  159. struct exynos_drm_display_ops *ops;
  160. void *ctx;
  161. };
  162. /*
  163. * Exynos drm manager ops
  164. *
  165. * @dpms: control device power.
  166. * @mode_fixup: fix mode data before applying it
  167. * @mode_set: set the given mode to the manager
  168. * @commit: set current hw specific display mode to hw.
  169. * @enable_vblank: specific driver callback for enabling vblank interrupt.
  170. * @disable_vblank: specific driver callback for disabling vblank interrupt.
  171. * @wait_for_vblank: wait for vblank interrupt to make sure that
  172. * hardware overlay is updated.
  173. * @win_mode_set: copy drm overlay info to hw specific overlay info.
  174. * @win_commit: apply hardware specific overlay data to registers.
  175. * @win_enable: enable hardware specific overlay.
  176. * @win_disable: disable hardware specific overlay.
  177. */
  178. struct exynos_drm_manager;
  179. struct exynos_drm_manager_ops {
  180. void (*dpms)(struct exynos_drm_manager *mgr, int mode);
  181. bool (*mode_fixup)(struct exynos_drm_manager *mgr,
  182. const struct drm_display_mode *mode,
  183. struct drm_display_mode *adjusted_mode);
  184. void (*mode_set)(struct exynos_drm_manager *mgr,
  185. const struct drm_display_mode *mode);
  186. void (*commit)(struct exynos_drm_manager *mgr);
  187. int (*enable_vblank)(struct exynos_drm_manager *mgr);
  188. void (*disable_vblank)(struct exynos_drm_manager *mgr);
  189. void (*wait_for_vblank)(struct exynos_drm_manager *mgr);
  190. void (*win_mode_set)(struct exynos_drm_manager *mgr,
  191. struct exynos_drm_overlay *overlay);
  192. void (*win_commit)(struct exynos_drm_manager *mgr, int zpos);
  193. void (*win_enable)(struct exynos_drm_manager *mgr, int zpos);
  194. void (*win_disable)(struct exynos_drm_manager *mgr, int zpos);
  195. };
  196. /*
  197. * Exynos drm common manager structure, maps 1:1 with a crtc
  198. *
  199. * @list: the list entry for this manager
  200. * @type: one of EXYNOS_DISPLAY_TYPE_LCD and HDMI.
  201. * @drm_dev: pointer to the drm device
  202. * @crtc: crtc object.
  203. * @pipe: the pipe number for this crtc/manager
  204. * @ops: pointer to callbacks for exynos drm specific functionality
  205. * @ctx: A pointer to the manager's implementation specific context
  206. */
  207. struct exynos_drm_manager {
  208. struct list_head list;
  209. enum exynos_drm_output_type type;
  210. struct drm_device *drm_dev;
  211. struct drm_crtc *crtc;
  212. int pipe;
  213. struct exynos_drm_manager_ops *ops;
  214. void *ctx;
  215. };
  216. struct exynos_drm_g2d_private {
  217. struct device *dev;
  218. struct list_head inuse_cmdlist;
  219. struct list_head event_list;
  220. struct list_head userptr_list;
  221. };
  222. struct exynos_drm_ipp_private {
  223. struct device *dev;
  224. struct list_head event_list;
  225. };
  226. struct drm_exynos_file_private {
  227. struct exynos_drm_g2d_private *g2d_priv;
  228. struct exynos_drm_ipp_private *ipp_priv;
  229. struct file *anon_filp;
  230. };
  231. /*
  232. * Exynos drm private structure.
  233. *
  234. * @da_start: start address to device address space.
  235. * with iommu, device address space starts from this address
  236. * otherwise default one.
  237. * @da_space_size: size of device address space.
  238. * if 0 then default value is used for it.
  239. * @pipe: the pipe number for this crtc/manager.
  240. */
  241. struct exynos_drm_private {
  242. struct drm_fb_helper *fb_helper;
  243. /* list head for new event to be added. */
  244. struct list_head pageflip_event_list;
  245. /*
  246. * created crtc object would be contained at this array and
  247. * this array is used to be aware of which crtc did it request vblank.
  248. */
  249. struct drm_crtc *crtc[MAX_CRTC];
  250. struct drm_property *plane_zpos_property;
  251. struct drm_property *crtc_mode_property;
  252. unsigned long da_start;
  253. unsigned long da_space_size;
  254. unsigned int pipe;
  255. };
  256. /*
  257. * Exynos drm sub driver structure.
  258. *
  259. * @list: sub driver has its own list object to register to exynos drm driver.
  260. * @dev: pointer to device object for subdrv device driver.
  261. * @drm_dev: pointer to drm_device and this pointer would be set
  262. * when sub driver calls exynos_drm_subdrv_register().
  263. * @manager: subdrv has its own manager to control a hardware appropriately
  264. * and we can access a hardware drawing on this manager.
  265. * @probe: this callback would be called by exynos drm driver after
  266. * subdrv is registered to it.
  267. * @remove: this callback is used to release resources created
  268. * by probe callback.
  269. * @open: this would be called with drm device file open.
  270. * @close: this would be called with drm device file close.
  271. */
  272. struct exynos_drm_subdrv {
  273. struct list_head list;
  274. struct device *dev;
  275. struct drm_device *drm_dev;
  276. int (*probe)(struct drm_device *drm_dev, struct device *dev);
  277. void (*remove)(struct drm_device *drm_dev, struct device *dev);
  278. int (*open)(struct drm_device *drm_dev, struct device *dev,
  279. struct drm_file *file);
  280. void (*close)(struct drm_device *drm_dev, struct device *dev,
  281. struct drm_file *file);
  282. };
  283. /* This function would be called by non kms drivers such as g2d and ipp. */
  284. int exynos_drm_subdrv_register(struct exynos_drm_subdrv *drm_subdrv);
  285. /* this function removes subdrv list from exynos drm driver */
  286. int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *drm_subdrv);
  287. int exynos_drm_device_subdrv_probe(struct drm_device *dev);
  288. int exynos_drm_device_subdrv_remove(struct drm_device *dev);
  289. int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
  290. void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
  291. /*
  292. * this function registers exynos drm hdmi platform device. It ensures only one
  293. * instance of the device is created.
  294. */
  295. int exynos_platform_device_hdmi_register(void);
  296. /*
  297. * this function unregisters exynos drm hdmi platform device if it exists.
  298. */
  299. void exynos_platform_device_hdmi_unregister(void);
  300. /*
  301. * this function registers exynos drm ipp platform device.
  302. */
  303. int exynos_platform_device_ipp_register(void);
  304. /*
  305. * this function unregisters exynos drm ipp platform device if it exists.
  306. */
  307. void exynos_platform_device_ipp_unregister(void);
  308. #ifdef CONFIG_DRM_EXYNOS_DPI
  309. struct exynos_drm_display * exynos_dpi_probe(struct device *dev);
  310. int exynos_dpi_remove(struct device *dev);
  311. #else
  312. static inline struct exynos_drm_display *
  313. exynos_dpi_probe(struct device *dev) { return NULL; }
  314. static inline int exynos_dpi_remove(struct device *dev) { return 0; }
  315. #endif
  316. /*
  317. * this function registers exynos drm vidi platform device/driver.
  318. */
  319. int exynos_drm_probe_vidi(void);
  320. /*
  321. * this function unregister exynos drm vidi platform device/driver.
  322. */
  323. void exynos_drm_remove_vidi(void);
  324. /* This function creates a encoder and a connector, and initializes them. */
  325. int exynos_drm_create_enc_conn(struct drm_device *dev,
  326. struct exynos_drm_display *display);
  327. int exynos_drm_component_add(struct device *dev,
  328. enum exynos_drm_device_type dev_type,
  329. enum exynos_drm_output_type out_type);
  330. void exynos_drm_component_del(struct device *dev,
  331. enum exynos_drm_device_type dev_type);
  332. extern struct platform_driver fimd_driver;
  333. extern struct platform_driver dp_driver;
  334. extern struct platform_driver dsi_driver;
  335. extern struct platform_driver mixer_driver;
  336. extern struct platform_driver hdmi_driver;
  337. extern struct platform_driver exynos_drm_common_hdmi_driver;
  338. extern struct platform_driver vidi_driver;
  339. extern struct platform_driver g2d_driver;
  340. extern struct platform_driver fimc_driver;
  341. extern struct platform_driver rotator_driver;
  342. extern struct platform_driver gsc_driver;
  343. extern struct platform_driver ipp_driver;
  344. #endif