drm.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. };
  66. static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
  67. {
  68. return container_of(client, struct tegra_dc, client);
  69. }
  70. static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
  71. {
  72. return container_of(crtc, struct tegra_dc, base);
  73. }
  74. static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
  75. unsigned long reg)
  76. {
  77. writel(value, dc->regs + (reg << 2));
  78. }
  79. static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
  80. unsigned long reg)
  81. {
  82. return readl(dc->regs + (reg << 2));
  83. }
  84. struct tegra_dc_window {
  85. struct {
  86. unsigned int x;
  87. unsigned int y;
  88. unsigned int w;
  89. unsigned int h;
  90. } src;
  91. struct {
  92. unsigned int x;
  93. unsigned int y;
  94. unsigned int w;
  95. unsigned int h;
  96. } dst;
  97. unsigned int bits_per_pixel;
  98. unsigned int format;
  99. unsigned int stride[2];
  100. unsigned long base[3];
  101. };
  102. /* from dc.c */
  103. extern unsigned int tegra_dc_format(uint32_t format);
  104. extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
  105. const struct tegra_dc_window *window);
  106. extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
  107. extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
  108. struct tegra_output_ops {
  109. int (*enable)(struct tegra_output *output);
  110. int (*disable)(struct tegra_output *output);
  111. int (*setup_clock)(struct tegra_output *output, struct clk *clk,
  112. unsigned long pclk);
  113. int (*check_mode)(struct tegra_output *output,
  114. struct drm_display_mode *mode,
  115. enum drm_mode_status *status);
  116. };
  117. enum tegra_output_type {
  118. TEGRA_OUTPUT_RGB,
  119. TEGRA_OUTPUT_HDMI,
  120. };
  121. struct tegra_output {
  122. struct device_node *of_node;
  123. struct device *dev;
  124. const struct tegra_output_ops *ops;
  125. enum tegra_output_type type;
  126. struct i2c_adapter *ddc;
  127. const struct edid *edid;
  128. unsigned int hpd_irq;
  129. int hpd_gpio;
  130. struct drm_encoder encoder;
  131. struct drm_connector connector;
  132. };
  133. static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
  134. {
  135. return container_of(e, struct tegra_output, encoder);
  136. }
  137. static inline struct tegra_output *connector_to_output(struct drm_connector *c)
  138. {
  139. return container_of(c, struct tegra_output, connector);
  140. }
  141. static inline int tegra_output_enable(struct tegra_output *output)
  142. {
  143. if (output && output->ops && output->ops->enable)
  144. return output->ops->enable(output);
  145. return output ? -ENOSYS : -EINVAL;
  146. }
  147. static inline int tegra_output_disable(struct tegra_output *output)
  148. {
  149. if (output && output->ops && output->ops->disable)
  150. return output->ops->disable(output);
  151. return output ? -ENOSYS : -EINVAL;
  152. }
  153. static inline int tegra_output_setup_clock(struct tegra_output *output,
  154. struct clk *clk, unsigned long pclk)
  155. {
  156. if (output && output->ops && output->ops->setup_clock)
  157. return output->ops->setup_clock(output, clk, pclk);
  158. return output ? -ENOSYS : -EINVAL;
  159. }
  160. static inline int tegra_output_check_mode(struct tegra_output *output,
  161. struct drm_display_mode *mode,
  162. enum drm_mode_status *status)
  163. {
  164. if (output && output->ops && output->ops->check_mode)
  165. return output->ops->check_mode(output, mode, status);
  166. return output ? -ENOSYS : -EINVAL;
  167. }
  168. /* from rgb.c */
  169. extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
  170. extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
  171. extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
  172. /* from output.c */
  173. extern int tegra_output_parse_dt(struct tegra_output *output);
  174. extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
  175. extern int tegra_output_exit(struct tegra_output *output);
  176. /* from fb.c */
  177. extern int tegra_drm_fb_init(struct drm_device *drm);
  178. extern void tegra_drm_fb_exit(struct drm_device *drm);
  179. extern struct platform_driver tegra_host1x_driver;
  180. extern struct platform_driver tegra_hdmi_driver;
  181. extern struct platform_driver tegra_dc_driver;
  182. extern struct drm_driver tegra_drm_driver;
  183. #endif /* TEGRA_DRM_H */