drm.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 <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_fixed.h>
  16. #include <uapi/drm/tegra_drm.h>
  17. #include "host1x.h"
  18. struct tegra_fb {
  19. struct drm_framebuffer base;
  20. struct tegra_bo **planes;
  21. unsigned int num_planes;
  22. };
  23. struct tegra_fbdev {
  24. struct drm_fb_helper base;
  25. struct tegra_fb *fb;
  26. };
  27. struct tegra_drm {
  28. struct drm_device *drm;
  29. struct device *dev;
  30. struct mutex subdevs_lock;
  31. struct list_head subdevs;
  32. struct list_head active;
  33. struct mutex clients_lock;
  34. struct list_head clients;
  35. struct tegra_fbdev *fbdev;
  36. };
  37. struct host1x_client;
  38. struct tegra_drm_context {
  39. struct host1x_client *client;
  40. struct host1x_channel *channel;
  41. struct list_head list;
  42. };
  43. struct host1x_client_ops {
  44. int (*drm_init)(struct host1x_client *client, struct drm_device *drm);
  45. int (*drm_exit)(struct host1x_client *client);
  46. int (*open_channel)(struct host1x_client *client,
  47. struct tegra_drm_context *context);
  48. void (*close_channel)(struct tegra_drm_context *context);
  49. int (*submit)(struct tegra_drm_context *context,
  50. struct drm_tegra_submit *args, struct drm_device *drm,
  51. struct drm_file *file);
  52. };
  53. struct host1x_client {
  54. struct tegra_drm *tegra;
  55. struct device *dev;
  56. const struct host1x_client_ops *ops;
  57. enum host1x_class class;
  58. struct host1x_channel *channel;
  59. struct host1x_syncpt **syncpts;
  60. unsigned int num_syncpts;
  61. struct list_head list;
  62. };
  63. extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
  64. extern int tegra_drm_exit(struct tegra_drm *tegra);
  65. extern int host1x_register_client(struct tegra_drm *tegra,
  66. struct host1x_client *client);
  67. extern int host1x_unregister_client(struct tegra_drm *tegra,
  68. struct host1x_client *client);
  69. struct tegra_output;
  70. struct tegra_dc {
  71. struct host1x_client client;
  72. struct device *dev;
  73. spinlock_t lock;
  74. struct drm_crtc base;
  75. int pipe;
  76. struct clk *clk;
  77. void __iomem *regs;
  78. int irq;
  79. struct tegra_output *rgb;
  80. struct list_head list;
  81. struct drm_info_list *debugfs_files;
  82. struct drm_minor *minor;
  83. struct dentry *debugfs;
  84. /* page-flip handling */
  85. struct drm_pending_vblank_event *event;
  86. };
  87. static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
  88. {
  89. return container_of(client, struct tegra_dc, client);
  90. }
  91. static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
  92. {
  93. return container_of(crtc, struct tegra_dc, base);
  94. }
  95. static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
  96. unsigned long reg)
  97. {
  98. writel(value, dc->regs + (reg << 2));
  99. }
  100. static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
  101. unsigned long reg)
  102. {
  103. return readl(dc->regs + (reg << 2));
  104. }
  105. struct tegra_dc_window {
  106. struct {
  107. unsigned int x;
  108. unsigned int y;
  109. unsigned int w;
  110. unsigned int h;
  111. } src;
  112. struct {
  113. unsigned int x;
  114. unsigned int y;
  115. unsigned int w;
  116. unsigned int h;
  117. } dst;
  118. unsigned int bits_per_pixel;
  119. unsigned int format;
  120. unsigned int stride[2];
  121. unsigned long base[3];
  122. };
  123. /* from dc.c */
  124. extern unsigned int tegra_dc_format(uint32_t format);
  125. extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
  126. const struct tegra_dc_window *window);
  127. extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
  128. extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
  129. extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
  130. struct drm_file *file);
  131. struct tegra_output_ops {
  132. int (*enable)(struct tegra_output *output);
  133. int (*disable)(struct tegra_output *output);
  134. int (*setup_clock)(struct tegra_output *output, struct clk *clk,
  135. unsigned long pclk);
  136. int (*check_mode)(struct tegra_output *output,
  137. struct drm_display_mode *mode,
  138. enum drm_mode_status *status);
  139. };
  140. enum tegra_output_type {
  141. TEGRA_OUTPUT_RGB,
  142. TEGRA_OUTPUT_HDMI,
  143. };
  144. struct tegra_output {
  145. struct device_node *of_node;
  146. struct device *dev;
  147. const struct tegra_output_ops *ops;
  148. enum tegra_output_type type;
  149. struct i2c_adapter *ddc;
  150. const struct edid *edid;
  151. unsigned int hpd_irq;
  152. int hpd_gpio;
  153. struct drm_encoder encoder;
  154. struct drm_connector connector;
  155. };
  156. static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
  157. {
  158. return container_of(e, struct tegra_output, encoder);
  159. }
  160. static inline struct tegra_output *connector_to_output(struct drm_connector *c)
  161. {
  162. return container_of(c, struct tegra_output, connector);
  163. }
  164. static inline int tegra_output_enable(struct tegra_output *output)
  165. {
  166. if (output && output->ops && output->ops->enable)
  167. return output->ops->enable(output);
  168. return output ? -ENOSYS : -EINVAL;
  169. }
  170. static inline int tegra_output_disable(struct tegra_output *output)
  171. {
  172. if (output && output->ops && output->ops->disable)
  173. return output->ops->disable(output);
  174. return output ? -ENOSYS : -EINVAL;
  175. }
  176. static inline int tegra_output_setup_clock(struct tegra_output *output,
  177. struct clk *clk, unsigned long pclk)
  178. {
  179. if (output && output->ops && output->ops->setup_clock)
  180. return output->ops->setup_clock(output, clk, pclk);
  181. return output ? -ENOSYS : -EINVAL;
  182. }
  183. static inline int tegra_output_check_mode(struct tegra_output *output,
  184. struct drm_display_mode *mode,
  185. enum drm_mode_status *status)
  186. {
  187. if (output && output->ops && output->ops->check_mode)
  188. return output->ops->check_mode(output, mode, status);
  189. return output ? -ENOSYS : -EINVAL;
  190. }
  191. /* from rgb.c */
  192. extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
  193. extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
  194. extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
  195. /* from output.c */
  196. extern int tegra_output_parse_dt(struct tegra_output *output);
  197. extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
  198. extern int tegra_output_exit(struct tegra_output *output);
  199. /* from fb.c */
  200. struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
  201. unsigned int index);
  202. extern int tegra_drm_fb_init(struct drm_device *drm);
  203. extern void tegra_drm_fb_exit(struct drm_device *drm);
  204. extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
  205. extern struct drm_driver tegra_drm_driver;
  206. #endif /* HOST1X_DRM_H */