drm.h 7.5 KB

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