Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Avionic Design GmbH |
| 3 | * Copyright (C) 2012 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 TEGRA_DRM_H |
| 11 | #define TEGRA_DRM_H 1 |
| 12 | |
| 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_gem_cma_helper.h> |
| 18 | #include <drm/drm_fb_cma_helper.h> |
| 19 | #include <drm/drm_fixed.h> |
| 20 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 21 | struct host1x { |
| 22 | struct drm_device *drm; |
| 23 | struct device *dev; |
| 24 | void __iomem *regs; |
| 25 | struct clk *clk; |
| 26 | int syncpt; |
| 27 | int irq; |
| 28 | |
| 29 | struct mutex drm_clients_lock; |
| 30 | struct list_head drm_clients; |
| 31 | struct list_head drm_active; |
| 32 | |
| 33 | struct mutex clients_lock; |
| 34 | struct list_head clients; |
| 35 | |
| 36 | struct drm_fbdev_cma *fbdev; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct host1x_client; |
| 40 | |
| 41 | struct host1x_client_ops { |
| 42 | int (*drm_init)(struct host1x_client *client, struct drm_device *drm); |
| 43 | int (*drm_exit)(struct host1x_client *client); |
| 44 | }; |
| 45 | |
| 46 | struct host1x_client { |
| 47 | struct host1x *host1x; |
| 48 | struct device *dev; |
| 49 | |
| 50 | const struct host1x_client_ops *ops; |
| 51 | |
| 52 | struct list_head list; |
| 53 | }; |
| 54 | |
| 55 | extern int host1x_drm_init(struct host1x *host1x, struct drm_device *drm); |
| 56 | extern int host1x_drm_exit(struct host1x *host1x); |
| 57 | |
| 58 | extern int host1x_register_client(struct host1x *host1x, |
| 59 | struct host1x_client *client); |
| 60 | extern int host1x_unregister_client(struct host1x *host1x, |
| 61 | struct host1x_client *client); |
| 62 | |
| 63 | struct tegra_output; |
| 64 | |
| 65 | struct tegra_dc { |
| 66 | struct host1x_client client; |
| 67 | |
| 68 | struct host1x *host1x; |
| 69 | struct device *dev; |
| 70 | |
| 71 | struct drm_crtc base; |
| 72 | int pipe; |
| 73 | |
| 74 | struct clk *clk; |
| 75 | |
| 76 | void __iomem *regs; |
| 77 | int irq; |
| 78 | |
| 79 | struct tegra_output *rgb; |
| 80 | |
| 81 | struct list_head list; |
| 82 | |
| 83 | struct drm_info_list *debugfs_files; |
| 84 | struct drm_minor *minor; |
| 85 | struct dentry *debugfs; |
| 86 | }; |
| 87 | |
| 88 | static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client) |
| 89 | { |
| 90 | return container_of(client, struct tegra_dc, client); |
| 91 | } |
| 92 | |
| 93 | static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc) |
| 94 | { |
| 95 | return container_of(crtc, struct tegra_dc, base); |
| 96 | } |
| 97 | |
| 98 | static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value, |
| 99 | unsigned long reg) |
| 100 | { |
| 101 | writel(value, dc->regs + (reg << 2)); |
| 102 | } |
| 103 | |
| 104 | static inline unsigned long tegra_dc_readl(struct tegra_dc *dc, |
| 105 | unsigned long reg) |
| 106 | { |
| 107 | return readl(dc->regs + (reg << 2)); |
| 108 | } |
| 109 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame^] | 110 | struct tegra_dc_window { |
| 111 | struct { |
| 112 | unsigned int x; |
| 113 | unsigned int y; |
| 114 | unsigned int w; |
| 115 | unsigned int h; |
| 116 | } src; |
| 117 | struct { |
| 118 | unsigned int x; |
| 119 | unsigned int y; |
| 120 | unsigned int w; |
| 121 | unsigned int h; |
| 122 | } dst; |
| 123 | unsigned int bits_per_pixel; |
| 124 | unsigned int format; |
| 125 | unsigned int stride[2]; |
| 126 | unsigned long base[3]; |
| 127 | }; |
| 128 | |
| 129 | /* from dc.c */ |
| 130 | extern unsigned int tegra_dc_format(uint32_t format); |
| 131 | extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index, |
| 132 | const struct tegra_dc_window *window); |
| 133 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 134 | struct tegra_output_ops { |
| 135 | int (*enable)(struct tegra_output *output); |
| 136 | int (*disable)(struct tegra_output *output); |
| 137 | int (*setup_clock)(struct tegra_output *output, struct clk *clk, |
| 138 | unsigned long pclk); |
| 139 | int (*check_mode)(struct tegra_output *output, |
| 140 | struct drm_display_mode *mode, |
| 141 | enum drm_mode_status *status); |
| 142 | }; |
| 143 | |
| 144 | enum tegra_output_type { |
| 145 | TEGRA_OUTPUT_RGB, |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 146 | TEGRA_OUTPUT_HDMI, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | struct tegra_output { |
| 150 | struct device_node *of_node; |
| 151 | struct device *dev; |
| 152 | |
| 153 | const struct tegra_output_ops *ops; |
| 154 | enum tegra_output_type type; |
| 155 | |
| 156 | struct i2c_adapter *ddc; |
| 157 | const struct edid *edid; |
| 158 | unsigned int hpd_irq; |
| 159 | int hpd_gpio; |
| 160 | |
| 161 | struct drm_encoder encoder; |
| 162 | struct drm_connector connector; |
| 163 | }; |
| 164 | |
| 165 | static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) |
| 166 | { |
| 167 | return container_of(e, struct tegra_output, encoder); |
| 168 | } |
| 169 | |
| 170 | static inline struct tegra_output *connector_to_output(struct drm_connector *c) |
| 171 | { |
| 172 | return container_of(c, struct tegra_output, connector); |
| 173 | } |
| 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 | |
| 180 | return output ? -ENOSYS : -EINVAL; |
| 181 | } |
| 182 | |
| 183 | static inline int tegra_output_disable(struct tegra_output *output) |
| 184 | { |
| 185 | if (output && output->ops && output->ops->disable) |
| 186 | return output->ops->disable(output); |
| 187 | |
| 188 | return output ? -ENOSYS : -EINVAL; |
| 189 | } |
| 190 | |
| 191 | static inline int tegra_output_setup_clock(struct tegra_output *output, |
| 192 | struct clk *clk, unsigned long pclk) |
| 193 | { |
| 194 | if (output && output->ops && output->ops->setup_clock) |
| 195 | return output->ops->setup_clock(output, clk, pclk); |
| 196 | |
| 197 | return output ? -ENOSYS : -EINVAL; |
| 198 | } |
| 199 | |
| 200 | static inline int tegra_output_check_mode(struct tegra_output *output, |
| 201 | struct drm_display_mode *mode, |
| 202 | enum drm_mode_status *status) |
| 203 | { |
| 204 | if (output && output->ops && output->ops->check_mode) |
| 205 | return output->ops->check_mode(output, mode, status); |
| 206 | |
| 207 | return output ? -ENOSYS : -EINVAL; |
| 208 | } |
| 209 | |
| 210 | /* from rgb.c */ |
| 211 | extern int tegra_dc_rgb_probe(struct tegra_dc *dc); |
| 212 | extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc); |
| 213 | extern int tegra_dc_rgb_exit(struct tegra_dc *dc); |
| 214 | |
| 215 | /* from output.c */ |
| 216 | extern int tegra_output_parse_dt(struct tegra_output *output); |
| 217 | extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output); |
| 218 | extern int tegra_output_exit(struct tegra_output *output); |
| 219 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 220 | /* from fb.c */ |
| 221 | extern int tegra_drm_fb_init(struct drm_device *drm); |
| 222 | extern void tegra_drm_fb_exit(struct drm_device *drm); |
| 223 | |
| 224 | extern struct platform_driver tegra_host1x_driver; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 225 | extern struct platform_driver tegra_hdmi_driver; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 226 | extern struct platform_driver tegra_dc_driver; |
| 227 | extern struct drm_driver tegra_drm_driver; |
| 228 | |
| 229 | #endif /* TEGRA_DRM_H */ |