drm.h 6.6 KB

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