Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Avionic Design GmbH |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 3 | * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved. |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 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 | |
Terje Bergstrom | 4231c6b | 2013-03-22 16:34:05 +0200 | [diff] [blame] | 10 | #ifndef HOST1X_DRM_H |
| 11 | #define HOST1X_DRM_H 1 |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 12 | |
Thierry Reding | e1e9064 | 2013-09-24 13:59:01 +0200 | [diff] [blame] | 13 | #include <uapi/drm/tegra_drm.h> |
| 14 | #include <linux/host1x.h> |
| 15 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 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> |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 20 | #include <drm/drm_fixed.h> |
| 21 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 22 | struct tegra_fb { |
| 23 | struct drm_framebuffer base; |
| 24 | struct tegra_bo **planes; |
| 25 | unsigned int num_planes; |
| 26 | }; |
| 27 | |
| 28 | struct tegra_fbdev { |
| 29 | struct drm_fb_helper base; |
| 30 | struct tegra_fb *fb; |
| 31 | }; |
| 32 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 33 | struct tegra_drm { |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 34 | struct drm_device *drm; |
| 35 | struct device *dev; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 36 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 37 | struct mutex subdevs_lock; |
| 38 | struct list_head subdevs; |
| 39 | struct list_head active; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 40 | |
| 41 | struct mutex clients_lock; |
| 42 | struct list_head clients; |
| 43 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 44 | struct tegra_fbdev *fbdev; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame^] | 47 | struct tegra_drm_client; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 48 | |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 49 | struct tegra_drm_context { |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame^] | 50 | struct tegra_drm_client *client; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 51 | struct host1x_channel *channel; |
| 52 | struct list_head list; |
| 53 | }; |
| 54 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame^] | 55 | struct tegra_drm_client_ops { |
| 56 | int (*open_channel)(struct tegra_drm_client *client, |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 57 | struct tegra_drm_context *context); |
| 58 | void (*close_channel)(struct tegra_drm_context *context); |
| 59 | int (*submit)(struct tegra_drm_context *context, |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 60 | struct drm_tegra_submit *args, struct drm_device *drm, |
| 61 | struct drm_file *file); |
| 62 | }; |
| 63 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame^] | 64 | struct tegra_drm_client { |
| 65 | struct host1x_client base; |
| 66 | struct drm_device *drm; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 67 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame^] | 68 | const struct tegra_drm_client_ops *ops; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame^] | 71 | static inline struct tegra_drm_client * |
| 72 | to_tegra_drm_client(struct host1x_client *client) |
| 73 | { |
| 74 | return container_of(client, struct tegra_drm_client, base); |
| 75 | } |
| 76 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 77 | extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); |
| 78 | extern int tegra_drm_exit(struct tegra_drm *tegra); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 79 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 80 | extern int host1x_register_client(struct tegra_drm *tegra, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 81 | struct host1x_client *client); |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 82 | extern int host1x_unregister_client(struct tegra_drm *tegra, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 83 | struct host1x_client *client); |
| 84 | |
| 85 | struct tegra_output; |
| 86 | |
| 87 | struct tegra_dc { |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame^] | 88 | struct tegra_drm_client client; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 89 | struct device *dev; |
Thierry Reding | d18d303 | 2013-09-26 16:09:19 +0200 | [diff] [blame] | 90 | spinlock_t lock; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 91 | |
| 92 | struct drm_crtc base; |
| 93 | int pipe; |
| 94 | |
| 95 | struct clk *clk; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 96 | void __iomem *regs; |
| 97 | int irq; |
| 98 | |
| 99 | struct tegra_output *rgb; |
| 100 | |
| 101 | struct list_head list; |
| 102 | |
| 103 | struct drm_info_list *debugfs_files; |
| 104 | struct drm_minor *minor; |
| 105 | struct dentry *debugfs; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 106 | |
| 107 | /* page-flip handling */ |
| 108 | struct drm_pending_vblank_event *event; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame^] | 111 | static inline struct tegra_dc * |
| 112 | tegra_drm_client_to_dc(struct tegra_drm_client *client) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 113 | { |
| 114 | return container_of(client, struct tegra_dc, client); |
| 115 | } |
| 116 | |
| 117 | static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc) |
| 118 | { |
| 119 | return container_of(crtc, struct tegra_dc, base); |
| 120 | } |
| 121 | |
| 122 | static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value, |
| 123 | unsigned long reg) |
| 124 | { |
| 125 | writel(value, dc->regs + (reg << 2)); |
| 126 | } |
| 127 | |
| 128 | static inline unsigned long tegra_dc_readl(struct tegra_dc *dc, |
| 129 | unsigned long reg) |
| 130 | { |
| 131 | return readl(dc->regs + (reg << 2)); |
| 132 | } |
| 133 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 134 | struct tegra_dc_window { |
| 135 | struct { |
| 136 | unsigned int x; |
| 137 | unsigned int y; |
| 138 | unsigned int w; |
| 139 | unsigned int h; |
| 140 | } src; |
| 141 | struct { |
| 142 | unsigned int x; |
| 143 | unsigned int y; |
| 144 | unsigned int w; |
| 145 | unsigned int h; |
| 146 | } dst; |
| 147 | unsigned int bits_per_pixel; |
| 148 | unsigned int format; |
| 149 | unsigned int stride[2]; |
| 150 | unsigned long base[3]; |
| 151 | }; |
| 152 | |
| 153 | /* from dc.c */ |
| 154 | extern unsigned int tegra_dc_format(uint32_t format); |
| 155 | extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index, |
| 156 | const struct tegra_dc_window *window); |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 157 | extern void tegra_dc_enable_vblank(struct tegra_dc *dc); |
| 158 | extern void tegra_dc_disable_vblank(struct tegra_dc *dc); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 159 | extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, |
| 160 | struct drm_file *file); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 161 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 162 | struct tegra_output_ops { |
| 163 | int (*enable)(struct tegra_output *output); |
| 164 | int (*disable)(struct tegra_output *output); |
| 165 | int (*setup_clock)(struct tegra_output *output, struct clk *clk, |
| 166 | unsigned long pclk); |
| 167 | int (*check_mode)(struct tegra_output *output, |
| 168 | struct drm_display_mode *mode, |
| 169 | enum drm_mode_status *status); |
| 170 | }; |
| 171 | |
| 172 | enum tegra_output_type { |
| 173 | TEGRA_OUTPUT_RGB, |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 174 | TEGRA_OUTPUT_HDMI, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | struct tegra_output { |
| 178 | struct device_node *of_node; |
| 179 | struct device *dev; |
| 180 | |
| 181 | const struct tegra_output_ops *ops; |
| 182 | enum tegra_output_type type; |
| 183 | |
| 184 | struct i2c_adapter *ddc; |
| 185 | const struct edid *edid; |
| 186 | unsigned int hpd_irq; |
| 187 | int hpd_gpio; |
| 188 | |
| 189 | struct drm_encoder encoder; |
| 190 | struct drm_connector connector; |
| 191 | }; |
| 192 | |
| 193 | static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) |
| 194 | { |
| 195 | return container_of(e, struct tegra_output, encoder); |
| 196 | } |
| 197 | |
| 198 | static inline struct tegra_output *connector_to_output(struct drm_connector *c) |
| 199 | { |
| 200 | return container_of(c, struct tegra_output, connector); |
| 201 | } |
| 202 | |
| 203 | static inline int tegra_output_enable(struct tegra_output *output) |
| 204 | { |
| 205 | if (output && output->ops && output->ops->enable) |
| 206 | return output->ops->enable(output); |
| 207 | |
| 208 | return output ? -ENOSYS : -EINVAL; |
| 209 | } |
| 210 | |
| 211 | static inline int tegra_output_disable(struct tegra_output *output) |
| 212 | { |
| 213 | if (output && output->ops && output->ops->disable) |
| 214 | return output->ops->disable(output); |
| 215 | |
| 216 | return output ? -ENOSYS : -EINVAL; |
| 217 | } |
| 218 | |
| 219 | static inline int tegra_output_setup_clock(struct tegra_output *output, |
| 220 | struct clk *clk, unsigned long pclk) |
| 221 | { |
| 222 | if (output && output->ops && output->ops->setup_clock) |
| 223 | return output->ops->setup_clock(output, clk, pclk); |
| 224 | |
| 225 | return output ? -ENOSYS : -EINVAL; |
| 226 | } |
| 227 | |
| 228 | static inline int tegra_output_check_mode(struct tegra_output *output, |
| 229 | struct drm_display_mode *mode, |
| 230 | enum drm_mode_status *status) |
| 231 | { |
| 232 | if (output && output->ops && output->ops->check_mode) |
| 233 | return output->ops->check_mode(output, mode, status); |
| 234 | |
| 235 | return output ? -ENOSYS : -EINVAL; |
| 236 | } |
| 237 | |
| 238 | /* from rgb.c */ |
| 239 | extern int tegra_dc_rgb_probe(struct tegra_dc *dc); |
| 240 | extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc); |
| 241 | extern int tegra_dc_rgb_exit(struct tegra_dc *dc); |
| 242 | |
| 243 | /* from output.c */ |
| 244 | extern int tegra_output_parse_dt(struct tegra_output *output); |
| 245 | extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output); |
| 246 | extern int tegra_output_exit(struct tegra_output *output); |
| 247 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 248 | /* from fb.c */ |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 249 | struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, |
| 250 | unsigned int index); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 251 | extern int tegra_drm_fb_init(struct drm_device *drm); |
| 252 | extern void tegra_drm_fb_exit(struct drm_device *drm); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 253 | extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 254 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 255 | extern struct drm_driver tegra_drm_driver; |
| 256 | |
Terje Bergstrom | 4231c6b | 2013-03-22 16:34:05 +0200 | [diff] [blame] | 257 | #endif /* HOST1X_DRM_H */ |