drm.h 6.4 KB

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