drm.h 7.6 KB

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