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 16 #include <drm/drmP.h> 17 #include <drm/drm_crtc_helper.h> 18 #include <drm/drm_edid.h> 19 #include <drm/drm_fb_helper.h> 20 #include <drm/drm_fixed.h> 21 22 struct reset_control; 23 24 struct tegra_fb { 25 struct drm_framebuffer base; 26 struct tegra_bo **planes; 27 unsigned int num_planes; 28 }; 29 30 #ifdef CONFIG_DRM_TEGRA_FBDEV 31 struct tegra_fbdev { 32 struct drm_fb_helper base; 33 struct tegra_fb *fb; 34 }; 35 #endif 36 37 struct tegra_drm { 38 struct drm_device *drm; 39 40 struct mutex clients_lock; 41 struct list_head clients; 42 43 #ifdef CONFIG_DRM_TEGRA_FBDEV 44 struct tegra_fbdev *fbdev; 45 #endif 46 }; 47 48 struct tegra_drm_client; 49 50 struct tegra_drm_context { 51 struct tegra_drm_client *client; 52 struct host1x_channel *channel; 53 struct list_head list; 54 }; 55 56 struct tegra_drm_client_ops { 57 int (*open_channel)(struct tegra_drm_client *client, 58 struct tegra_drm_context *context); 59 void (*close_channel)(struct tegra_drm_context *context); 60 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset); 61 int (*submit)(struct tegra_drm_context *context, 62 struct drm_tegra_submit *args, struct drm_device *drm, 63 struct drm_file *file); 64 }; 65 66 int tegra_drm_submit(struct tegra_drm_context *context, 67 struct drm_tegra_submit *args, struct drm_device *drm, 68 struct drm_file *file); 69 70 struct tegra_drm_client { 71 struct host1x_client base; 72 struct list_head list; 73 74 const struct tegra_drm_client_ops *ops; 75 }; 76 77 static inline struct tegra_drm_client * 78 host1x_to_drm_client(struct host1x_client *client) 79 { 80 return container_of(client, struct tegra_drm_client, base); 81 } 82 83 extern int tegra_drm_register_client(struct tegra_drm *tegra, 84 struct tegra_drm_client *client); 85 extern int tegra_drm_unregister_client(struct tegra_drm *tegra, 86 struct tegra_drm_client *client); 87 88 extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); 89 extern int tegra_drm_exit(struct tegra_drm *tegra); 90 91 struct tegra_dc_soc_info; 92 struct tegra_output; 93 94 struct tegra_dc { 95 struct host1x_client client; 96 struct device *dev; 97 spinlock_t lock; 98 99 struct drm_crtc base; 100 int pipe; 101 102 struct clk *clk; 103 struct reset_control *rst; 104 void __iomem *regs; 105 int irq; 106 107 struct tegra_output *rgb; 108 109 struct list_head list; 110 111 struct drm_info_list *debugfs_files; 112 struct drm_minor *minor; 113 struct dentry *debugfs; 114 115 /* page-flip handling */ 116 struct drm_pending_vblank_event *event; 117 118 const struct tegra_dc_soc_info *soc; 119 }; 120 121 static inline struct tegra_dc * 122 host1x_client_to_dc(struct host1x_client *client) 123 { 124 return container_of(client, struct tegra_dc, client); 125 } 126 127 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc) 128 { 129 return crtc ? container_of(crtc, struct tegra_dc, base) : NULL; 130 } 131 132 static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value, 133 unsigned long reg) 134 { 135 writel(value, dc->regs + (reg << 2)); 136 } 137 138 static inline unsigned long tegra_dc_readl(struct tegra_dc *dc, 139 unsigned long reg) 140 { 141 return readl(dc->regs + (reg << 2)); 142 } 143 144 struct tegra_dc_window { 145 struct { 146 unsigned int x; 147 unsigned int y; 148 unsigned int w; 149 unsigned int h; 150 } src; 151 struct { 152 unsigned int x; 153 unsigned int y; 154 unsigned int w; 155 unsigned int h; 156 } dst; 157 unsigned int bits_per_pixel; 158 unsigned int format; 159 unsigned int stride[2]; 160 unsigned long base[3]; 161 bool bottom_up; 162 bool tiled; 163 }; 164 165 /* from dc.c */ 166 extern unsigned int tegra_dc_format(uint32_t format); 167 extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index, 168 const struct tegra_dc_window *window); 169 extern void tegra_dc_enable_vblank(struct tegra_dc *dc); 170 extern void tegra_dc_disable_vblank(struct tegra_dc *dc); 171 extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, 172 struct drm_file *file); 173 174 struct tegra_output_ops { 175 int (*enable)(struct tegra_output *output); 176 int (*disable)(struct tegra_output *output); 177 int (*setup_clock)(struct tegra_output *output, struct clk *clk, 178 unsigned long pclk); 179 int (*check_mode)(struct tegra_output *output, 180 struct drm_display_mode *mode, 181 enum drm_mode_status *status); 182 enum drm_connector_status (*detect)(struct tegra_output *output); 183 }; 184 185 enum tegra_output_type { 186 TEGRA_OUTPUT_RGB, 187 TEGRA_OUTPUT_HDMI, 188 TEGRA_OUTPUT_DSI, 189 TEGRA_OUTPUT_EDP, 190 }; 191 192 struct tegra_output { 193 struct device_node *of_node; 194 struct device *dev; 195 196 const struct tegra_output_ops *ops; 197 enum tegra_output_type type; 198 199 struct drm_panel *panel; 200 struct i2c_adapter *ddc; 201 const struct edid *edid; 202 unsigned int hpd_irq; 203 int hpd_gpio; 204 205 struct drm_encoder encoder; 206 struct drm_connector connector; 207 }; 208 209 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) 210 { 211 return container_of(e, struct tegra_output, encoder); 212 } 213 214 static inline struct tegra_output *connector_to_output(struct drm_connector *c) 215 { 216 return container_of(c, struct tegra_output, connector); 217 } 218 219 static inline int tegra_output_enable(struct tegra_output *output) 220 { 221 if (output && output->ops && output->ops->enable) 222 return output->ops->enable(output); 223 224 return output ? -ENOSYS : -EINVAL; 225 } 226 227 static inline int tegra_output_disable(struct tegra_output *output) 228 { 229 if (output && output->ops && output->ops->disable) 230 return output->ops->disable(output); 231 232 return output ? -ENOSYS : -EINVAL; 233 } 234 235 static inline int tegra_output_setup_clock(struct tegra_output *output, 236 struct clk *clk, unsigned long pclk) 237 { 238 if (output && output->ops && output->ops->setup_clock) 239 return output->ops->setup_clock(output, clk, pclk); 240 241 return output ? -ENOSYS : -EINVAL; 242 } 243 244 static inline int tegra_output_check_mode(struct tegra_output *output, 245 struct drm_display_mode *mode, 246 enum drm_mode_status *status) 247 { 248 if (output && output->ops && output->ops->check_mode) 249 return output->ops->check_mode(output, mode, status); 250 251 return output ? -ENOSYS : -EINVAL; 252 } 253 254 /* from bus.c */ 255 int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device); 256 void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device); 257 258 /* from rgb.c */ 259 extern int tegra_dc_rgb_probe(struct tegra_dc *dc); 260 extern int tegra_dc_rgb_remove(struct tegra_dc *dc); 261 extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc); 262 extern int tegra_dc_rgb_exit(struct tegra_dc *dc); 263 264 /* from output.c */ 265 extern int tegra_output_probe(struct tegra_output *output); 266 extern int tegra_output_remove(struct tegra_output *output); 267 extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output); 268 extern int tegra_output_exit(struct tegra_output *output); 269 270 /* from dpaux.c */ 271 272 struct tegra_dpaux; 273 struct drm_dp_link; 274 struct drm_dp_aux; 275 276 struct tegra_dpaux *tegra_dpaux_find_by_of_node(struct device_node *np); 277 enum drm_connector_status tegra_dpaux_detect(struct tegra_dpaux *dpaux); 278 int tegra_dpaux_attach(struct tegra_dpaux *dpaux, struct tegra_output *output); 279 int tegra_dpaux_detach(struct tegra_dpaux *dpaux); 280 int tegra_dpaux_enable(struct tegra_dpaux *dpaux); 281 int tegra_dpaux_disable(struct tegra_dpaux *dpaux); 282 int tegra_dpaux_prepare(struct tegra_dpaux *dpaux, u8 encoding); 283 int tegra_dpaux_train(struct tegra_dpaux *dpaux, struct drm_dp_link *link, 284 u8 pattern); 285 286 /* from fb.c */ 287 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, 288 unsigned int index); 289 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer); 290 bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer); 291 extern int tegra_drm_fb_init(struct drm_device *drm); 292 extern void tegra_drm_fb_exit(struct drm_device *drm); 293 #ifdef CONFIG_DRM_TEGRA_FBDEV 294 extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev); 295 #endif 296 297 extern struct platform_driver tegra_dc_driver; 298 extern struct platform_driver tegra_dsi_driver; 299 extern struct platform_driver tegra_sor_driver; 300 extern struct platform_driver tegra_hdmi_driver; 301 extern struct platform_driver tegra_dpaux_driver; 302 extern struct platform_driver tegra_gr2d_driver; 303 extern struct platform_driver tegra_gr3d_driver; 304 305 #endif /* HOST1X_DRM_H */ 306