1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2012 Avionic Design GmbH 4 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved. 5 */ 6 7 #ifndef HOST1X_DRM_H 8 #define HOST1X_DRM_H 1 9 10 #include <linux/host1x.h> 11 #include <linux/iova.h> 12 #include <linux/of_gpio.h> 13 14 #include <drm/drm_atomic.h> 15 #include <drm/drm_edid.h> 16 #include <drm/drm_encoder.h> 17 #include <drm/drm_fb_helper.h> 18 #include <drm/drm_fixed.h> 19 #include <drm/drm_probe_helper.h> 20 #include <uapi/drm/tegra_drm.h> 21 22 #include "gem.h" 23 #include "hub.h" 24 #include "trace.h" 25 26 struct reset_control; 27 28 #ifdef CONFIG_DRM_FBDEV_EMULATION 29 struct tegra_fbdev { 30 struct drm_fb_helper base; 31 struct drm_framebuffer *fb; 32 }; 33 #endif 34 35 struct tegra_drm { 36 struct drm_device *drm; 37 38 struct iommu_domain *domain; 39 struct mutex mm_lock; 40 struct drm_mm mm; 41 42 struct { 43 struct iova_domain domain; 44 unsigned long shift; 45 unsigned long limit; 46 } carveout; 47 48 struct mutex clients_lock; 49 struct list_head clients; 50 51 #ifdef CONFIG_DRM_FBDEV_EMULATION 52 struct tegra_fbdev *fbdev; 53 #endif 54 55 unsigned int pitch_align; 56 57 struct tegra_display_hub *hub; 58 }; 59 60 struct tegra_drm_client; 61 62 struct tegra_drm_context { 63 struct tegra_drm_client *client; 64 struct host1x_channel *channel; 65 unsigned int id; 66 }; 67 68 struct tegra_drm_client_ops { 69 int (*open_channel)(struct tegra_drm_client *client, 70 struct tegra_drm_context *context); 71 void (*close_channel)(struct tegra_drm_context *context); 72 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset); 73 int (*is_valid_class)(u32 class); 74 int (*submit)(struct tegra_drm_context *context, 75 struct drm_tegra_submit *args, struct drm_device *drm, 76 struct drm_file *file); 77 }; 78 79 int tegra_drm_submit(struct tegra_drm_context *context, 80 struct drm_tegra_submit *args, struct drm_device *drm, 81 struct drm_file *file); 82 83 struct tegra_drm_client { 84 struct host1x_client base; 85 struct list_head list; 86 struct tegra_drm *drm; 87 88 unsigned int version; 89 const struct tegra_drm_client_ops *ops; 90 }; 91 92 static inline struct tegra_drm_client * 93 host1x_to_drm_client(struct host1x_client *client) 94 { 95 return container_of(client, struct tegra_drm_client, base); 96 } 97 98 int tegra_drm_register_client(struct tegra_drm *tegra, 99 struct tegra_drm_client *client); 100 int tegra_drm_unregister_client(struct tegra_drm *tegra, 101 struct tegra_drm_client *client); 102 int host1x_client_iommu_attach(struct host1x_client *client); 103 void host1x_client_iommu_detach(struct host1x_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 void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova); 109 void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt, 110 dma_addr_t iova); 111 112 struct cec_notifier; 113 114 struct tegra_output { 115 struct device_node *of_node; 116 struct device *dev; 117 118 struct drm_panel *panel; 119 struct i2c_adapter *ddc; 120 const struct edid *edid; 121 struct cec_notifier *cec; 122 unsigned int hpd_irq; 123 struct gpio_desc *hpd_gpio; 124 125 struct drm_encoder encoder; 126 struct drm_connector connector; 127 }; 128 129 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) 130 { 131 return container_of(e, struct tegra_output, encoder); 132 } 133 134 static inline struct tegra_output *connector_to_output(struct drm_connector *c) 135 { 136 return container_of(c, struct tegra_output, connector); 137 } 138 139 /* from output.c */ 140 int tegra_output_probe(struct tegra_output *output); 141 void tegra_output_remove(struct tegra_output *output); 142 int tegra_output_init(struct drm_device *drm, struct tegra_output *output); 143 void tegra_output_exit(struct tegra_output *output); 144 void tegra_output_find_possible_crtcs(struct tegra_output *output, 145 struct drm_device *drm); 146 147 int tegra_output_connector_get_modes(struct drm_connector *connector); 148 enum drm_connector_status 149 tegra_output_connector_detect(struct drm_connector *connector, bool force); 150 void tegra_output_connector_destroy(struct drm_connector *connector); 151 152 void tegra_output_encoder_destroy(struct drm_encoder *encoder); 153 154 /* from dpaux.c */ 155 struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np); 156 enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux); 157 int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output); 158 int drm_dp_aux_detach(struct drm_dp_aux *aux); 159 int drm_dp_aux_enable(struct drm_dp_aux *aux); 160 int drm_dp_aux_disable(struct drm_dp_aux *aux); 161 162 /* from fb.c */ 163 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, 164 unsigned int index); 165 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer); 166 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer, 167 struct tegra_bo_tiling *tiling); 168 struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, 169 struct drm_file *file, 170 const struct drm_mode_fb_cmd2 *cmd); 171 int tegra_drm_fb_prepare(struct drm_device *drm); 172 void tegra_drm_fb_free(struct drm_device *drm); 173 int tegra_drm_fb_init(struct drm_device *drm); 174 void tegra_drm_fb_exit(struct drm_device *drm); 175 176 extern struct platform_driver tegra_display_hub_driver; 177 extern struct platform_driver tegra_dc_driver; 178 extern struct platform_driver tegra_hdmi_driver; 179 extern struct platform_driver tegra_dsi_driver; 180 extern struct platform_driver tegra_dpaux_driver; 181 extern struct platform_driver tegra_sor_driver; 182 extern struct platform_driver tegra_gr2d_driver; 183 extern struct platform_driver tegra_gr3d_driver; 184 extern struct platform_driver tegra_vic_driver; 185 186 #endif /* HOST1X_DRM_H */ 187