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 10 #ifndef HOST1X_DRM_H 11 #define HOST1X_DRM_H 1 12 13 #include <uapi/drm/tegra_drm.h> 14 #include <linux/host1x.h> 15 #include <linux/of_gpio.h> 16 17 #include <drm/drmP.h> 18 #include <drm/drm_crtc_helper.h> 19 #include <drm/drm_edid.h> 20 #include <drm/drm_encoder.h> 21 #include <drm/drm_fb_helper.h> 22 #include <drm/drm_fixed.h> 23 24 #include "gem.h" 25 26 struct reset_control; 27 28 struct tegra_fb { 29 struct drm_framebuffer base; 30 struct tegra_bo **planes; 31 unsigned int num_planes; 32 }; 33 34 #ifdef CONFIG_DRM_FBDEV_EMULATION 35 struct tegra_fbdev { 36 struct drm_fb_helper base; 37 struct tegra_fb *fb; 38 }; 39 #endif 40 41 struct tegra_drm { 42 struct drm_device *drm; 43 44 struct iommu_domain *domain; 45 struct drm_mm mm; 46 47 struct mutex clients_lock; 48 struct list_head clients; 49 50 #ifdef CONFIG_DRM_FBDEV_EMULATION 51 struct tegra_fbdev *fbdev; 52 #endif 53 54 unsigned int pitch_align; 55 56 struct { 57 struct drm_atomic_state *state; 58 struct work_struct work; 59 struct mutex lock; 60 } commit; 61 62 struct drm_atomic_state *state; 63 }; 64 65 struct tegra_drm_client; 66 67 struct tegra_drm_context { 68 struct tegra_drm_client *client; 69 struct host1x_channel *channel; 70 struct list_head list; 71 }; 72 73 struct tegra_drm_client_ops { 74 int (*open_channel)(struct tegra_drm_client *client, 75 struct tegra_drm_context *context); 76 void (*close_channel)(struct tegra_drm_context *context); 77 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset); 78 int (*submit)(struct tegra_drm_context *context, 79 struct drm_tegra_submit *args, struct drm_device *drm, 80 struct drm_file *file); 81 }; 82 83 int tegra_drm_submit(struct tegra_drm_context *context, 84 struct drm_tegra_submit *args, struct drm_device *drm, 85 struct drm_file *file); 86 87 struct tegra_drm_client { 88 struct host1x_client base; 89 struct list_head list; 90 91 const struct tegra_drm_client_ops *ops; 92 }; 93 94 static inline struct tegra_drm_client * 95 host1x_to_drm_client(struct host1x_client *client) 96 { 97 return container_of(client, struct tegra_drm_client, base); 98 } 99 100 int tegra_drm_register_client(struct tegra_drm *tegra, 101 struct tegra_drm_client *client); 102 int tegra_drm_unregister_client(struct tegra_drm *tegra, 103 struct tegra_drm_client *client); 104 105 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); 106 int tegra_drm_exit(struct tegra_drm *tegra); 107 108 struct tegra_dc_soc_info; 109 struct tegra_output; 110 111 struct tegra_dc_stats { 112 unsigned long frames; 113 unsigned long vblank; 114 unsigned long underflow; 115 unsigned long overflow; 116 }; 117 118 struct tegra_dc { 119 struct host1x_client client; 120 struct host1x_syncpt *syncpt; 121 struct device *dev; 122 spinlock_t lock; 123 124 struct drm_crtc base; 125 unsigned int powergate; 126 int pipe; 127 128 struct clk *clk; 129 struct reset_control *rst; 130 void __iomem *regs; 131 int irq; 132 133 struct tegra_output *rgb; 134 135 struct tegra_dc_stats stats; 136 struct list_head list; 137 138 struct drm_info_list *debugfs_files; 139 struct drm_minor *minor; 140 struct dentry *debugfs; 141 142 /* page-flip handling */ 143 struct drm_pending_vblank_event *event; 144 145 const struct tegra_dc_soc_info *soc; 146 147 struct iommu_domain *domain; 148 }; 149 150 static inline struct tegra_dc * 151 host1x_client_to_dc(struct host1x_client *client) 152 { 153 return container_of(client, struct tegra_dc, client); 154 } 155 156 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc) 157 { 158 return crtc ? container_of(crtc, struct tegra_dc, base) : NULL; 159 } 160 161 static inline void tegra_dc_writel(struct tegra_dc *dc, u32 value, 162 unsigned long offset) 163 { 164 writel(value, dc->regs + (offset << 2)); 165 } 166 167 static inline u32 tegra_dc_readl(struct tegra_dc *dc, unsigned long offset) 168 { 169 return readl(dc->regs + (offset << 2)); 170 } 171 172 struct tegra_dc_window { 173 struct { 174 unsigned int x; 175 unsigned int y; 176 unsigned int w; 177 unsigned int h; 178 } src; 179 struct { 180 unsigned int x; 181 unsigned int y; 182 unsigned int w; 183 unsigned int h; 184 } dst; 185 unsigned int bits_per_pixel; 186 unsigned int stride[2]; 187 unsigned long base[3]; 188 bool bottom_up; 189 190 struct tegra_bo_tiling tiling; 191 u32 format; 192 u32 swap; 193 }; 194 195 /* from dc.c */ 196 u32 tegra_dc_get_vblank_counter(struct tegra_dc *dc); 197 void tegra_dc_enable_vblank(struct tegra_dc *dc); 198 void tegra_dc_disable_vblank(struct tegra_dc *dc); 199 void tegra_dc_commit(struct tegra_dc *dc); 200 int tegra_dc_state_setup_clock(struct tegra_dc *dc, 201 struct drm_crtc_state *crtc_state, 202 struct clk *clk, unsigned long pclk, 203 unsigned int div); 204 205 struct tegra_output { 206 struct device_node *of_node; 207 struct device *dev; 208 209 struct drm_panel *panel; 210 struct i2c_adapter *ddc; 211 const struct edid *edid; 212 unsigned int hpd_irq; 213 int hpd_gpio; 214 enum of_gpio_flags hpd_gpio_flags; 215 216 struct drm_encoder encoder; 217 struct drm_connector connector; 218 }; 219 220 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) 221 { 222 return container_of(e, struct tegra_output, encoder); 223 } 224 225 static inline struct tegra_output *connector_to_output(struct drm_connector *c) 226 { 227 return container_of(c, struct tegra_output, connector); 228 } 229 230 /* from rgb.c */ 231 int tegra_dc_rgb_probe(struct tegra_dc *dc); 232 int tegra_dc_rgb_remove(struct tegra_dc *dc); 233 int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc); 234 int tegra_dc_rgb_exit(struct tegra_dc *dc); 235 236 /* from output.c */ 237 int tegra_output_probe(struct tegra_output *output); 238 void tegra_output_remove(struct tegra_output *output); 239 int tegra_output_init(struct drm_device *drm, struct tegra_output *output); 240 void tegra_output_exit(struct tegra_output *output); 241 242 int tegra_output_connector_get_modes(struct drm_connector *connector); 243 enum drm_connector_status 244 tegra_output_connector_detect(struct drm_connector *connector, bool force); 245 void tegra_output_connector_destroy(struct drm_connector *connector); 246 247 void tegra_output_encoder_destroy(struct drm_encoder *encoder); 248 249 /* from dpaux.c */ 250 struct drm_dp_link; 251 252 struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np); 253 enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux); 254 int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output); 255 int drm_dp_aux_detach(struct drm_dp_aux *aux); 256 int drm_dp_aux_enable(struct drm_dp_aux *aux); 257 int drm_dp_aux_disable(struct drm_dp_aux *aux); 258 int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding); 259 int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link, 260 u8 pattern); 261 262 /* from fb.c */ 263 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, 264 unsigned int index); 265 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer); 266 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer, 267 struct tegra_bo_tiling *tiling); 268 struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, 269 struct drm_file *file, 270 const struct drm_mode_fb_cmd2 *cmd); 271 int tegra_drm_fb_prepare(struct drm_device *drm); 272 void tegra_drm_fb_free(struct drm_device *drm); 273 int tegra_drm_fb_init(struct drm_device *drm); 274 void tegra_drm_fb_exit(struct drm_device *drm); 275 void tegra_drm_fb_suspend(struct drm_device *drm); 276 void tegra_drm_fb_resume(struct drm_device *drm); 277 #ifdef CONFIG_DRM_FBDEV_EMULATION 278 void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev); 279 void tegra_fb_output_poll_changed(struct drm_device *drm); 280 #endif 281 282 extern struct platform_driver tegra_dc_driver; 283 extern struct platform_driver tegra_hdmi_driver; 284 extern struct platform_driver tegra_dsi_driver; 285 extern struct platform_driver tegra_dpaux_driver; 286 extern struct platform_driver tegra_sor_driver; 287 extern struct platform_driver tegra_gr2d_driver; 288 extern struct platform_driver tegra_gr3d_driver; 289 290 #endif /* HOST1X_DRM_H */ 291