drm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Copyright (C) 2012 Avionic Design GmbH
  3. * Copyright (C) 2012 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 TEGRA_DRM_H
  10. #define TEGRA_DRM_H 1
  11. #include <drm/drmP.h>
  12. #include <drm/drm_crtc_helper.h>
  13. #include <drm/drm_edid.h>
  14. #include <drm/drm_fb_helper.h>
  15. #include <drm/drm_gem_cma_helper.h>
  16. #include <drm/drm_fb_cma_helper.h>
  17. #include <drm/drm_fixed.h>
  18. struct host1x {
  19. struct drm_device *drm;
  20. struct device *dev;
  21. void __iomem *regs;
  22. struct clk *clk;
  23. int syncpt;
  24. int irq;
  25. struct mutex drm_clients_lock;
  26. struct list_head drm_clients;
  27. struct list_head drm_active;
  28. struct mutex clients_lock;
  29. struct list_head clients;
  30. struct drm_fbdev_cma *fbdev;
  31. };
  32. struct host1x_client;
  33. struct host1x_client_ops {
  34. int (*drm_init)(struct host1x_client *client, struct drm_device *drm);
  35. int (*drm_exit)(struct host1x_client *client);
  36. };
  37. struct host1x_client {
  38. struct host1x *host1x;
  39. struct device *dev;
  40. const struct host1x_client_ops *ops;
  41. struct list_head list;
  42. };
  43. extern int host1x_drm_init(struct host1x *host1x, struct drm_device *drm);
  44. extern int host1x_drm_exit(struct host1x *host1x);
  45. extern int host1x_register_client(struct host1x *host1x,
  46. struct host1x_client *client);
  47. extern int host1x_unregister_client(struct host1x *host1x,
  48. struct host1x_client *client);
  49. struct tegra_output;
  50. struct tegra_dc {
  51. struct host1x_client client;
  52. spinlock_t lock;
  53. struct host1x *host1x;
  54. struct device *dev;
  55. struct drm_crtc base;
  56. int pipe;
  57. struct clk *clk;
  58. void __iomem *regs;
  59. int irq;
  60. struct tegra_output *rgb;
  61. struct list_head list;
  62. struct drm_info_list *debugfs_files;
  63. struct drm_minor *minor;
  64. struct dentry *debugfs;
  65. /* page-flip handling */
  66. struct drm_pending_vblank_event *event;
  67. };
  68. static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
  69. {
  70. return container_of(client, struct tegra_dc, client);
  71. }
  72. static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
  73. {
  74. return container_of(crtc, struct tegra_dc, base);
  75. }
  76. static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
  77. unsigned long reg)
  78. {
  79. writel(value, dc->regs + (reg << 2));
  80. }
  81. static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
  82. unsigned long reg)
  83. {
  84. return readl(dc->regs + (reg << 2));
  85. }
  86. struct tegra_dc_window {
  87. struct {
  88. unsigned int x;
  89. unsigned int y;
  90. unsigned int w;
  91. unsigned int h;
  92. } src;
  93. struct {
  94. unsigned int x;
  95. unsigned int y;
  96. unsigned int w;
  97. unsigned int h;
  98. } dst;
  99. unsigned int bits_per_pixel;
  100. unsigned int format;
  101. unsigned int stride[2];
  102. unsigned long base[3];
  103. };
  104. /* from dc.c */
  105. extern unsigned int tegra_dc_format(uint32_t format);
  106. extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
  107. const struct tegra_dc_window *window);
  108. extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
  109. extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
  110. extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
  111. struct drm_file *file);
  112. struct tegra_output_ops {
  113. int (*enable)(struct tegra_output *output);
  114. int (*disable)(struct tegra_output *output);
  115. int (*setup_clock)(struct tegra_output *output, struct clk *clk,
  116. unsigned long pclk);
  117. int (*check_mode)(struct tegra_output *output,
  118. struct drm_display_mode *mode,
  119. enum drm_mode_status *status);
  120. };
  121. enum tegra_output_type {
  122. TEGRA_OUTPUT_RGB,
  123. TEGRA_OUTPUT_HDMI,
  124. };
  125. struct tegra_output {
  126. struct device_node *of_node;
  127. struct device *dev;
  128. const struct tegra_output_ops *ops;
  129. enum tegra_output_type type;
  130. struct i2c_adapter *ddc;
  131. const struct edid *edid;
  132. unsigned int hpd_irq;
  133. int hpd_gpio;
  134. struct drm_encoder encoder;
  135. struct drm_connector connector;
  136. };
  137. static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
  138. {
  139. return container_of(e, struct tegra_output, encoder);
  140. }
  141. static inline struct tegra_output *connector_to_output(struct drm_connector *c)
  142. {
  143. return container_of(c, struct tegra_output, connector);
  144. }
  145. static inline int tegra_output_enable(struct tegra_output *output)
  146. {
  147. if (output && output->ops && output->ops->enable)
  148. return output->ops->enable(output);
  149. return output ? -ENOSYS : -EINVAL;
  150. }
  151. static inline int tegra_output_disable(struct tegra_output *output)
  152. {
  153. if (output && output->ops && output->ops->disable)
  154. return output->ops->disable(output);
  155. return output ? -ENOSYS : -EINVAL;
  156. }
  157. static inline int tegra_output_setup_clock(struct tegra_output *output,
  158. struct clk *clk, unsigned long pclk)
  159. {
  160. if (output && output->ops && output->ops->setup_clock)
  161. return output->ops->setup_clock(output, clk, pclk);
  162. return output ? -ENOSYS : -EINVAL;
  163. }
  164. static inline int tegra_output_check_mode(struct tegra_output *output,
  165. struct drm_display_mode *mode,
  166. enum drm_mode_status *status)
  167. {
  168. if (output && output->ops && output->ops->check_mode)
  169. return output->ops->check_mode(output, mode, status);
  170. return output ? -ENOSYS : -EINVAL;
  171. }
  172. /* from rgb.c */
  173. extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
  174. extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
  175. extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
  176. /* from output.c */
  177. extern int tegra_output_parse_dt(struct tegra_output *output);
  178. extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
  179. extern int tegra_output_exit(struct tegra_output *output);
  180. /* from fb.c */
  181. extern int tegra_drm_fb_init(struct drm_device *drm);
  182. extern void tegra_drm_fb_exit(struct drm_device *drm);
  183. extern struct platform_driver tegra_host1x_driver;
  184. extern struct platform_driver tegra_hdmi_driver;
  185. extern struct platform_driver tegra_dc_driver;
  186. extern struct drm_driver tegra_drm_driver;
  187. #endif /* TEGRA_DRM_H */