Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Avionic Design GmbH |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 4 | * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved. |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Terje Bergstrom | 4231c6b | 2013-03-22 16:34:05 +0200 | [diff] [blame] | 7 | #ifndef HOST1X_DRM_H |
| 8 | #define HOST1X_DRM_H 1 |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 9 | |
Thierry Reding | e1e9064 | 2013-09-24 13:59:01 +0200 | [diff] [blame] | 10 | #include <linux/host1x.h> |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 11 | #include <linux/iova.h> |
Thierry Reding | fb36d0ee | 2015-04-27 15:12:39 +0200 | [diff] [blame] | 12 | #include <linux/of_gpio.h> |
Thierry Reding | e1e9064 | 2013-09-24 13:59:01 +0200 | [diff] [blame] | 13 | |
Thierry Reding | c4755fb | 2017-11-13 11:08:13 +0100 | [diff] [blame] | 14 | #include <drm/drm_atomic.h> |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 15 | #include <drm/drm_edid.h> |
Laurent Pinchart | 9338203 | 2016-11-28 20:51:09 +0200 | [diff] [blame] | 16 | #include <drm/drm_encoder.h> |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 17 | #include <drm/drm_fb_helper.h> |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 18 | #include <drm/drm_fixed.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 19 | #include <drm/drm_probe_helper.h> |
Sam Ravnborg | eb1df69 | 2019-08-04 11:41:30 +0200 | [diff] [blame] | 20 | #include <uapi/drm/tegra_drm.h> |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 21 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 22 | #include "gem.h" |
Thierry Reding | c4755fb | 2017-11-13 11:08:13 +0100 | [diff] [blame] | 23 | #include "hub.h" |
Thierry Reding | 67e04d1 | 2017-08-15 15:41:10 +0200 | [diff] [blame] | 24 | #include "trace.h" |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 25 | |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 26 | struct reset_control; |
| 27 | |
Archit Taneja | b110ef3 | 2015-10-27 13:40:59 +0530 | [diff] [blame] | 28 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 29 | struct tegra_fbdev { |
| 30 | struct drm_fb_helper base; |
Daniel Stone | dbc33c7 | 2018-03-30 15:11:27 +0100 | [diff] [blame] | 31 | struct drm_framebuffer *fb; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 32 | }; |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 33 | #endif |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 34 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 35 | struct tegra_drm { |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 36 | struct drm_device *drm; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 37 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 38 | struct iommu_domain *domain; |
Thierry Reding | bc8828b | 2017-10-12 17:43:33 +0200 | [diff] [blame] | 39 | struct iommu_group *group; |
Thierry Reding | 347ad49d | 2017-03-09 20:04:56 +0100 | [diff] [blame] | 40 | struct mutex mm_lock; |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 41 | struct drm_mm mm; |
| 42 | |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 43 | struct { |
| 44 | struct iova_domain domain; |
| 45 | unsigned long shift; |
| 46 | unsigned long limit; |
| 47 | } carveout; |
| 48 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 49 | struct mutex clients_lock; |
| 50 | struct list_head clients; |
| 51 | |
Archit Taneja | b110ef3 | 2015-10-27 13:40:59 +0530 | [diff] [blame] | 52 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 53 | struct tegra_fbdev *fbdev; |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 54 | #endif |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 55 | |
| 56 | unsigned int pitch_align; |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 57 | |
Thierry Reding | c4755fb | 2017-11-13 11:08:13 +0100 | [diff] [blame] | 58 | struct tegra_display_hub *hub; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 61 | struct tegra_drm_client; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 62 | |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 63 | struct tegra_drm_context { |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 64 | struct tegra_drm_client *client; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 65 | struct host1x_channel *channel; |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 66 | unsigned int id; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 69 | struct tegra_drm_client_ops { |
| 70 | int (*open_channel)(struct tegra_drm_client *client, |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 71 | struct tegra_drm_context *context); |
| 72 | void (*close_channel)(struct tegra_drm_context *context); |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 73 | int (*is_addr_reg)(struct device *dev, u32 class, u32 offset); |
Dmitry Osipenko | 0f563a4 | 2017-06-15 02:18:37 +0300 | [diff] [blame] | 74 | int (*is_valid_class)(u32 class); |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 75 | int (*submit)(struct tegra_drm_context *context, |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 76 | struct drm_tegra_submit *args, struct drm_device *drm, |
| 77 | struct drm_file *file); |
| 78 | }; |
| 79 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 80 | int tegra_drm_submit(struct tegra_drm_context *context, |
| 81 | struct drm_tegra_submit *args, struct drm_device *drm, |
| 82 | struct drm_file *file); |
| 83 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 84 | struct tegra_drm_client { |
| 85 | struct host1x_client base; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 86 | struct list_head list; |
Thierry Reding | 8e5d19c | 2019-02-01 14:28:31 +0100 | [diff] [blame] | 87 | struct tegra_drm *drm; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 88 | |
Thierry Reding | f3b3cfc | 2018-05-16 17:05:04 +0200 | [diff] [blame] | 89 | unsigned int version; |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 90 | const struct tegra_drm_client_ops *ops; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 93 | static inline struct tegra_drm_client * |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 94 | host1x_to_drm_client(struct host1x_client *client) |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 95 | { |
| 96 | return container_of(client, struct tegra_drm_client, base); |
| 97 | } |
| 98 | |
Thierry Reding | 688c59a | 2014-04-16 09:54:21 +0200 | [diff] [blame] | 99 | int tegra_drm_register_client(struct tegra_drm *tegra, |
| 100 | struct tegra_drm_client *client); |
| 101 | int tegra_drm_unregister_client(struct tegra_drm *tegra, |
| 102 | struct tegra_drm_client *client); |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 103 | struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client, |
| 104 | bool shared); |
| 105 | void host1x_client_iommu_detach(struct host1x_client *client, |
| 106 | struct iommu_group *group); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 107 | |
Thierry Reding | 688c59a | 2014-04-16 09:54:21 +0200 | [diff] [blame] | 108 | int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); |
| 109 | int tegra_drm_exit(struct tegra_drm *tegra); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 110 | |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 111 | void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova); |
| 112 | void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt, |
| 113 | dma_addr_t iova); |
| 114 | |
Hans Verkuil | fb83be8 | 2017-09-11 14:29:52 +0200 | [diff] [blame] | 115 | struct cec_notifier; |
| 116 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 117 | struct tegra_output { |
| 118 | struct device_node *of_node; |
| 119 | struct device *dev; |
| 120 | |
Thierry Reding | 9be7d86 | 2013-08-30 15:22:36 +0200 | [diff] [blame] | 121 | struct drm_panel *panel; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 122 | struct i2c_adapter *ddc; |
| 123 | const struct edid *edid; |
Thierry Reding | f25d0a6 | 2018-12-10 17:34:54 +0100 | [diff] [blame] | 124 | struct cec_notifier *cec; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 125 | unsigned int hpd_irq; |
Thierry Reding | bbad640 | 2019-06-05 10:46:46 +0200 | [diff] [blame] | 126 | struct gpio_desc *hpd_gpio; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 127 | |
| 128 | struct drm_encoder encoder; |
| 129 | struct drm_connector connector; |
| 130 | }; |
| 131 | |
| 132 | static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) |
| 133 | { |
| 134 | return container_of(e, struct tegra_output, encoder); |
| 135 | } |
| 136 | |
| 137 | static inline struct tegra_output *connector_to_output(struct drm_connector *c) |
| 138 | { |
| 139 | return container_of(c, struct tegra_output, connector); |
| 140 | } |
| 141 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 142 | /* from output.c */ |
Thierry Reding | 688c59a | 2014-04-16 09:54:21 +0200 | [diff] [blame] | 143 | int tegra_output_probe(struct tegra_output *output); |
Thierry Reding | 328ec69 | 2014-12-19 15:55:08 +0100 | [diff] [blame] | 144 | void tegra_output_remove(struct tegra_output *output); |
Thierry Reding | 688c59a | 2014-04-16 09:54:21 +0200 | [diff] [blame] | 145 | int tegra_output_init(struct drm_device *drm, struct tegra_output *output); |
Thierry Reding | 328ec69 | 2014-12-19 15:55:08 +0100 | [diff] [blame] | 146 | void tegra_output_exit(struct tegra_output *output); |
Thierry Reding | c57997b | 2017-10-12 19:12:57 +0200 | [diff] [blame] | 147 | void tegra_output_find_possible_crtcs(struct tegra_output *output, |
| 148 | struct drm_device *drm); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 149 | |
Thierry Reding | 132085d | 2014-11-28 15:38:40 +0100 | [diff] [blame] | 150 | int tegra_output_connector_get_modes(struct drm_connector *connector); |
Thierry Reding | 132085d | 2014-11-28 15:38:40 +0100 | [diff] [blame] | 151 | enum drm_connector_status |
| 152 | tegra_output_connector_detect(struct drm_connector *connector, bool force); |
| 153 | void tegra_output_connector_destroy(struct drm_connector *connector); |
| 154 | |
| 155 | void tegra_output_encoder_destroy(struct drm_encoder *encoder); |
| 156 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 157 | /* from dpaux.c */ |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 158 | struct drm_dp_link; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 159 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 160 | struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np); |
| 161 | enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux); |
| 162 | int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output); |
| 163 | int drm_dp_aux_detach(struct drm_dp_aux *aux); |
| 164 | int drm_dp_aux_enable(struct drm_dp_aux *aux); |
| 165 | int drm_dp_aux_disable(struct drm_dp_aux *aux); |
| 166 | int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding); |
| 167 | int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link, |
| 168 | u8 pattern); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 169 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 170 | /* from fb.c */ |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 171 | struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, |
| 172 | unsigned int index); |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 173 | bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer); |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 174 | int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer, |
| 175 | struct tegra_bo_tiling *tiling); |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 176 | struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, |
| 177 | struct drm_file *file, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 178 | const struct drm_mode_fb_cmd2 *cmd); |
Thierry Reding | e2215321f | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 179 | int tegra_drm_fb_prepare(struct drm_device *drm); |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 180 | void tegra_drm_fb_free(struct drm_device *drm); |
Thierry Reding | 688c59a | 2014-04-16 09:54:21 +0200 | [diff] [blame] | 181 | int tegra_drm_fb_init(struct drm_device *drm); |
| 182 | void tegra_drm_fb_exit(struct drm_device *drm); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 183 | |
Thierry Reding | c4755fb | 2017-11-13 11:08:13 +0100 | [diff] [blame] | 184 | extern struct platform_driver tegra_display_hub_driver; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 185 | extern struct platform_driver tegra_dc_driver; |
| 186 | extern struct platform_driver tegra_hdmi_driver; |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 187 | extern struct platform_driver tegra_dsi_driver; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 188 | extern struct platform_driver tegra_dpaux_driver; |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 189 | extern struct platform_driver tegra_sor_driver; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 190 | extern struct platform_driver tegra_gr2d_driver; |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 191 | extern struct platform_driver tegra_gr3d_driver; |
Arto Merilainen | 0ae797a | 2016-12-14 13:16:13 +0200 | [diff] [blame] | 192 | extern struct platform_driver tegra_vic_driver; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 193 | |
Terje Bergstrom | 4231c6b | 2013-03-22 16:34:05 +0200 | [diff] [blame] | 194 | #endif /* HOST1X_DRM_H */ |