drm.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 tegra_framebuffer {
  19. struct drm_framebuffer base;
  20. struct drm_gem_cma_object *obj;
  21. };
  22. static inline struct tegra_framebuffer *to_tegra_fb(struct drm_framebuffer *fb)
  23. {
  24. return container_of(fb, struct tegra_framebuffer, base);
  25. }
  26. struct host1x {
  27. struct drm_device *drm;
  28. struct device *dev;
  29. void __iomem *regs;
  30. struct clk *clk;
  31. int syncpt;
  32. int irq;
  33. struct mutex drm_clients_lock;
  34. struct list_head drm_clients;
  35. struct list_head drm_active;
  36. struct mutex clients_lock;
  37. struct list_head clients;
  38. struct drm_fbdev_cma *fbdev;
  39. struct tegra_framebuffer fb;
  40. };
  41. struct host1x_client;
  42. struct host1x_client_ops {
  43. int (*drm_init)(struct host1x_client *client, struct drm_device *drm);
  44. int (*drm_exit)(struct host1x_client *client);
  45. };
  46. struct host1x_client {
  47. struct host1x *host1x;
  48. struct device *dev;
  49. const struct host1x_client_ops *ops;
  50. struct list_head list;
  51. };
  52. extern int host1x_drm_init(struct host1x *host1x, struct drm_device *drm);
  53. extern int host1x_drm_exit(struct host1x *host1x);
  54. extern int host1x_register_client(struct host1x *host1x,
  55. struct host1x_client *client);
  56. extern int host1x_unregister_client(struct host1x *host1x,
  57. struct host1x_client *client);
  58. struct tegra_output;
  59. struct tegra_dc {
  60. struct host1x_client client;
  61. struct host1x *host1x;
  62. struct device *dev;
  63. struct drm_crtc base;
  64. int pipe;
  65. struct clk *clk;
  66. void __iomem *regs;
  67. int irq;
  68. struct tegra_output *rgb;
  69. struct list_head list;
  70. struct drm_info_list *debugfs_files;
  71. struct drm_minor *minor;
  72. struct dentry *debugfs;
  73. };
  74. static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
  75. {
  76. return container_of(client, struct tegra_dc, client);
  77. }
  78. static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
  79. {
  80. return container_of(crtc, struct tegra_dc, base);
  81. }
  82. static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
  83. unsigned long reg)
  84. {
  85. writel(value, dc->regs + (reg << 2));
  86. }
  87. static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
  88. unsigned long reg)
  89. {
  90. return readl(dc->regs + (reg << 2));
  91. }
  92. struct tegra_output_ops {
  93. int (*enable)(struct tegra_output *output);
  94. int (*disable)(struct tegra_output *output);
  95. int (*setup_clock)(struct tegra_output *output, struct clk *clk,
  96. unsigned long pclk);
  97. int (*check_mode)(struct tegra_output *output,
  98. struct drm_display_mode *mode,
  99. enum drm_mode_status *status);
  100. };
  101. enum tegra_output_type {
  102. TEGRA_OUTPUT_RGB,
  103. TEGRA_OUTPUT_HDMI,
  104. };
  105. struct tegra_output {
  106. struct device_node *of_node;
  107. struct device *dev;
  108. const struct tegra_output_ops *ops;
  109. enum tegra_output_type type;
  110. struct i2c_adapter *ddc;
  111. const struct edid *edid;
  112. unsigned int hpd_irq;
  113. int hpd_gpio;
  114. struct drm_encoder encoder;
  115. struct drm_connector connector;
  116. };
  117. static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
  118. {
  119. return container_of(e, struct tegra_output, encoder);
  120. }
  121. static inline struct tegra_output *connector_to_output(struct drm_connector *c)
  122. {
  123. return container_of(c, struct tegra_output, connector);
  124. }
  125. static inline int tegra_output_enable(struct tegra_output *output)
  126. {
  127. if (output && output->ops && output->ops->enable)
  128. return output->ops->enable(output);
  129. return output ? -ENOSYS : -EINVAL;
  130. }
  131. static inline int tegra_output_disable(struct tegra_output *output)
  132. {
  133. if (output && output->ops && output->ops->disable)
  134. return output->ops->disable(output);
  135. return output ? -ENOSYS : -EINVAL;
  136. }
  137. static inline int tegra_output_setup_clock(struct tegra_output *output,
  138. struct clk *clk, unsigned long pclk)
  139. {
  140. if (output && output->ops && output->ops->setup_clock)
  141. return output->ops->setup_clock(output, clk, pclk);
  142. return output ? -ENOSYS : -EINVAL;
  143. }
  144. static inline int tegra_output_check_mode(struct tegra_output *output,
  145. struct drm_display_mode *mode,
  146. enum drm_mode_status *status)
  147. {
  148. if (output && output->ops && output->ops->check_mode)
  149. return output->ops->check_mode(output, mode, status);
  150. return output ? -ENOSYS : -EINVAL;
  151. }
  152. /* from rgb.c */
  153. extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
  154. extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
  155. extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
  156. /* from output.c */
  157. extern int tegra_output_parse_dt(struct tegra_output *output);
  158. extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
  159. extern int tegra_output_exit(struct tegra_output *output);
  160. /* from fb.c */
  161. extern int tegra_drm_fb_init(struct drm_device *drm);
  162. extern void tegra_drm_fb_exit(struct drm_device *drm);
  163. extern struct platform_driver tegra_host1x_driver;
  164. extern struct platform_driver tegra_hdmi_driver;
  165. extern struct platform_driver tegra_dc_driver;
  166. extern struct drm_driver tegra_drm_driver;
  167. #endif /* TEGRA_DRM_H */