drm.h 7.3 KB

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