drm.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * Copyright (C) 2012 Avionic Design GmbH
  3. * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef HOST1X_DRM_H
  10. #define HOST1X_DRM_H 1
  11. #include <uapi/drm/tegra_drm.h>
  12. #include <linux/host1x.h>
  13. #include <linux/of_gpio.h>
  14. #include <drm/drmP.h>
  15. #include <drm/drm_crtc_helper.h>
  16. #include <drm/drm_edid.h>
  17. #include <drm/drm_encoder.h>
  18. #include <drm/drm_fb_helper.h>
  19. #include <drm/drm_fixed.h>
  20. #include "gem.h"
  21. struct reset_control;
  22. struct tegra_fb {
  23. struct drm_framebuffer base;
  24. struct tegra_bo **planes;
  25. unsigned int num_planes;
  26. };
  27. #ifdef CONFIG_DRM_FBDEV_EMULATION
  28. struct tegra_fbdev {
  29. struct drm_fb_helper base;
  30. struct tegra_fb *fb;
  31. };
  32. #endif
  33. struct tegra_drm {
  34. struct drm_device *drm;
  35. struct iommu_domain *domain;
  36. struct mutex mm_lock;
  37. struct drm_mm mm;
  38. struct mutex clients_lock;
  39. struct list_head clients;
  40. #ifdef CONFIG_DRM_FBDEV_EMULATION
  41. struct tegra_fbdev *fbdev;
  42. #endif
  43. unsigned int pitch_align;
  44. struct {
  45. struct drm_atomic_state *state;
  46. struct work_struct work;
  47. struct mutex lock;
  48. } commit;
  49. struct drm_atomic_state *state;
  50. };
  51. struct tegra_drm_client;
  52. struct tegra_drm_context {
  53. struct tegra_drm_client *client;
  54. struct host1x_channel *channel;
  55. unsigned int id;
  56. };
  57. struct tegra_drm_client_ops {
  58. int (*open_channel)(struct tegra_drm_client *client,
  59. struct tegra_drm_context *context);
  60. void (*close_channel)(struct tegra_drm_context *context);
  61. int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
  62. int (*submit)(struct tegra_drm_context *context,
  63. struct drm_tegra_submit *args, struct drm_device *drm,
  64. struct drm_file *file);
  65. };
  66. int tegra_drm_submit(struct tegra_drm_context *context,
  67. struct drm_tegra_submit *args, struct drm_device *drm,
  68. struct drm_file *file);
  69. struct tegra_drm_client {
  70. struct host1x_client base;
  71. struct list_head list;
  72. const struct tegra_drm_client_ops *ops;
  73. };
  74. static inline struct tegra_drm_client *
  75. host1x_to_drm_client(struct host1x_client *client)
  76. {
  77. return container_of(client, struct tegra_drm_client, base);
  78. }
  79. int tegra_drm_register_client(struct tegra_drm *tegra,
  80. struct tegra_drm_client *client);
  81. int tegra_drm_unregister_client(struct tegra_drm *tegra,
  82. struct tegra_drm_client *client);
  83. int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
  84. int tegra_drm_exit(struct tegra_drm *tegra);
  85. struct tegra_dc_soc_info;
  86. struct tegra_output;
  87. struct tegra_dc_stats {
  88. unsigned long frames;
  89. unsigned long vblank;
  90. unsigned long underflow;
  91. unsigned long overflow;
  92. };
  93. struct tegra_dc {
  94. struct host1x_client client;
  95. struct host1x_syncpt *syncpt;
  96. struct device *dev;
  97. spinlock_t lock;
  98. struct drm_crtc base;
  99. unsigned int powergate;
  100. int pipe;
  101. struct clk *clk;
  102. struct reset_control *rst;
  103. void __iomem *regs;
  104. int irq;
  105. struct tegra_output *rgb;
  106. struct tegra_dc_stats stats;
  107. struct list_head list;
  108. struct drm_info_list *debugfs_files;
  109. struct drm_minor *minor;
  110. struct dentry *debugfs;
  111. /* page-flip handling */
  112. struct drm_pending_vblank_event *event;
  113. const struct tegra_dc_soc_info *soc;
  114. struct iommu_domain *domain;
  115. };
  116. static inline struct tegra_dc *
  117. host1x_client_to_dc(struct host1x_client *client)
  118. {
  119. return container_of(client, struct tegra_dc, client);
  120. }
  121. static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
  122. {
  123. return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
  124. }
  125. static inline void tegra_dc_writel(struct tegra_dc *dc, u32 value,
  126. unsigned long offset)
  127. {
  128. writel(value, dc->regs + (offset << 2));
  129. }
  130. static inline u32 tegra_dc_readl(struct tegra_dc *dc, unsigned long offset)
  131. {
  132. return readl(dc->regs + (offset << 2));
  133. }
  134. struct tegra_dc_window {
  135. struct {
  136. unsigned int x;
  137. unsigned int y;
  138. unsigned int w;
  139. unsigned int h;
  140. } src;
  141. struct {
  142. unsigned int x;
  143. unsigned int y;
  144. unsigned int w;
  145. unsigned int h;
  146. } dst;
  147. unsigned int bits_per_pixel;
  148. unsigned int stride[2];
  149. unsigned long base[3];
  150. bool bottom_up;
  151. struct tegra_bo_tiling tiling;
  152. u32 format;
  153. u32 swap;
  154. };
  155. /* from dc.c */
  156. u32 tegra_dc_get_vblank_counter(struct tegra_dc *dc);
  157. void tegra_dc_enable_vblank(struct tegra_dc *dc);
  158. void tegra_dc_disable_vblank(struct tegra_dc *dc);
  159. void tegra_dc_commit(struct tegra_dc *dc);
  160. int tegra_dc_state_setup_clock(struct tegra_dc *dc,
  161. struct drm_crtc_state *crtc_state,
  162. struct clk *clk, unsigned long pclk,
  163. unsigned int div);
  164. struct tegra_output {
  165. struct device_node *of_node;
  166. struct device *dev;
  167. struct drm_panel *panel;
  168. struct i2c_adapter *ddc;
  169. const struct edid *edid;
  170. unsigned int hpd_irq;
  171. int hpd_gpio;
  172. enum of_gpio_flags hpd_gpio_flags;
  173. struct drm_encoder encoder;
  174. struct drm_connector connector;
  175. };
  176. static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
  177. {
  178. return container_of(e, struct tegra_output, encoder);
  179. }
  180. static inline struct tegra_output *connector_to_output(struct drm_connector *c)
  181. {
  182. return container_of(c, struct tegra_output, connector);
  183. }
  184. /* from rgb.c */
  185. int tegra_dc_rgb_probe(struct tegra_dc *dc);
  186. int tegra_dc_rgb_remove(struct tegra_dc *dc);
  187. int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
  188. int tegra_dc_rgb_exit(struct tegra_dc *dc);
  189. /* from output.c */
  190. int tegra_output_probe(struct tegra_output *output);
  191. void tegra_output_remove(struct tegra_output *output);
  192. int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
  193. void tegra_output_exit(struct tegra_output *output);
  194. int tegra_output_connector_get_modes(struct drm_connector *connector);
  195. enum drm_connector_status
  196. tegra_output_connector_detect(struct drm_connector *connector, bool force);
  197. void tegra_output_connector_destroy(struct drm_connector *connector);
  198. void tegra_output_encoder_destroy(struct drm_encoder *encoder);
  199. /* from dpaux.c */
  200. struct drm_dp_link;
  201. struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
  202. enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
  203. int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
  204. int drm_dp_aux_detach(struct drm_dp_aux *aux);
  205. int drm_dp_aux_enable(struct drm_dp_aux *aux);
  206. int drm_dp_aux_disable(struct drm_dp_aux *aux);
  207. int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding);
  208. int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link,
  209. u8 pattern);
  210. /* from fb.c */
  211. struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
  212. unsigned int index);
  213. bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
  214. int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
  215. struct tegra_bo_tiling *tiling);
  216. struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
  217. struct drm_file *file,
  218. const struct drm_mode_fb_cmd2 *cmd);
  219. int tegra_drm_fb_prepare(struct drm_device *drm);
  220. void tegra_drm_fb_free(struct drm_device *drm);
  221. int tegra_drm_fb_init(struct drm_device *drm);
  222. void tegra_drm_fb_exit(struct drm_device *drm);
  223. void tegra_drm_fb_suspend(struct drm_device *drm);
  224. void tegra_drm_fb_resume(struct drm_device *drm);
  225. #ifdef CONFIG_DRM_FBDEV_EMULATION
  226. void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
  227. void tegra_fb_output_poll_changed(struct drm_device *drm);
  228. #endif
  229. extern struct platform_driver tegra_dc_driver;
  230. extern struct platform_driver tegra_hdmi_driver;
  231. extern struct platform_driver tegra_dsi_driver;
  232. extern struct platform_driver tegra_dpaux_driver;
  233. extern struct platform_driver tegra_sor_driver;
  234. extern struct platform_driver tegra_gr2d_driver;
  235. extern struct platform_driver tegra_gr3d_driver;
  236. #endif /* HOST1X_DRM_H */