drm.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. struct host1x *host1x;
  53. struct device *dev;
  54. struct drm_crtc base;
  55. int pipe;
  56. struct clk *clk;
  57. void __iomem *regs;
  58. int irq;
  59. struct tegra_output *rgb;
  60. struct list_head list;
  61. struct drm_info_list *debugfs_files;
  62. struct drm_minor *minor;
  63. struct dentry *debugfs;
  64. };
  65. static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
  66. {
  67. return container_of(client, struct tegra_dc, client);
  68. }
  69. static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
  70. {
  71. return container_of(crtc, struct tegra_dc, base);
  72. }
  73. static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
  74. unsigned long reg)
  75. {
  76. writel(value, dc->regs + (reg << 2));
  77. }
  78. static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
  79. unsigned long reg)
  80. {
  81. return readl(dc->regs + (reg << 2));
  82. }
  83. struct tegra_output_ops {
  84. int (*enable)(struct tegra_output *output);
  85. int (*disable)(struct tegra_output *output);
  86. int (*setup_clock)(struct tegra_output *output, struct clk *clk,
  87. unsigned long pclk);
  88. int (*check_mode)(struct tegra_output *output,
  89. struct drm_display_mode *mode,
  90. enum drm_mode_status *status);
  91. };
  92. enum tegra_output_type {
  93. TEGRA_OUTPUT_RGB,
  94. TEGRA_OUTPUT_HDMI,
  95. };
  96. struct tegra_output {
  97. struct device_node *of_node;
  98. struct device *dev;
  99. const struct tegra_output_ops *ops;
  100. enum tegra_output_type type;
  101. struct i2c_adapter *ddc;
  102. const struct edid *edid;
  103. unsigned int hpd_irq;
  104. int hpd_gpio;
  105. struct drm_encoder encoder;
  106. struct drm_connector connector;
  107. };
  108. static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
  109. {
  110. return container_of(e, struct tegra_output, encoder);
  111. }
  112. static inline struct tegra_output *connector_to_output(struct drm_connector *c)
  113. {
  114. return container_of(c, struct tegra_output, connector);
  115. }
  116. static inline int tegra_output_enable(struct tegra_output *output)
  117. {
  118. if (output && output->ops && output->ops->enable)
  119. return output->ops->enable(output);
  120. return output ? -ENOSYS : -EINVAL;
  121. }
  122. static inline int tegra_output_disable(struct tegra_output *output)
  123. {
  124. if (output && output->ops && output->ops->disable)
  125. return output->ops->disable(output);
  126. return output ? -ENOSYS : -EINVAL;
  127. }
  128. static inline int tegra_output_setup_clock(struct tegra_output *output,
  129. struct clk *clk, unsigned long pclk)
  130. {
  131. if (output && output->ops && output->ops->setup_clock)
  132. return output->ops->setup_clock(output, clk, pclk);
  133. return output ? -ENOSYS : -EINVAL;
  134. }
  135. static inline int tegra_output_check_mode(struct tegra_output *output,
  136. struct drm_display_mode *mode,
  137. enum drm_mode_status *status)
  138. {
  139. if (output && output->ops && output->ops->check_mode)
  140. return output->ops->check_mode(output, mode, status);
  141. return output ? -ENOSYS : -EINVAL;
  142. }
  143. /* from rgb.c */
  144. extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
  145. extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
  146. extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
  147. /* from output.c */
  148. extern int tegra_output_parse_dt(struct tegra_output *output);
  149. extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
  150. extern int tegra_output_exit(struct tegra_output *output);
  151. /* from fb.c */
  152. extern int tegra_drm_fb_init(struct drm_device *drm);
  153. extern void tegra_drm_fb_exit(struct drm_device *drm);
  154. extern struct platform_driver tegra_host1x_driver;
  155. extern struct platform_driver tegra_hdmi_driver;
  156. extern struct platform_driver tegra_dc_driver;
  157. extern struct drm_driver tegra_drm_driver;
  158. #endif /* TEGRA_DRM_H */