drm.h 7.0 KB

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