1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2dee8268fSThierry Reding /* 3dee8268fSThierry Reding * Copyright (C) 2012 Avionic Design GmbH 4dee8268fSThierry Reding * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved. 5dee8268fSThierry Reding */ 6dee8268fSThierry Reding 7dee8268fSThierry Reding #ifndef HOST1X_DRM_H 8dee8268fSThierry Reding #define HOST1X_DRM_H 1 9dee8268fSThierry Reding 10dee8268fSThierry Reding #include <linux/host1x.h> 11ad926015SMikko Perttunen #include <linux/iova.h> 12ac2caae6SLinus Walleij #include <linux/gpio/consumer.h> 13dee8268fSThierry Reding 14c4755fb9SThierry Reding #include <drm/drm_atomic.h> 15f00b9dd5SDmitry Osipenko #include <drm/drm_bridge.h> 16dee8268fSThierry Reding #include <drm/drm_edid.h> 179338203cSLaurent Pinchart #include <drm/drm_encoder.h> 18dee8268fSThierry Reding #include <drm/drm_fb_helper.h> 19dee8268fSThierry Reding #include <drm/drm_fixed.h> 20fcd70cd3SDaniel Vetter #include <drm/drm_probe_helper.h> 21eb1df694SSam Ravnborg #include <uapi/drm/tegra_drm.h> 22dee8268fSThierry Reding 23c134f019SThierry Reding #include "gem.h" 24c4755fb9SThierry Reding #include "hub.h" 2567e04d1aSThierry Reding #include "trace.h" 26c134f019SThierry Reding 277b6f8467SThierry Reding /* XXX move to include/uapi/drm/drm_fourcc.h? */ 28671cc352SDmitry Osipenko #define DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT BIT_ULL(22) 297b6f8467SThierry Reding 30ca48080aSStephen Warren struct reset_control; 31ca48080aSStephen Warren 32b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION 33dee8268fSThierry Reding struct tegra_fbdev { 34dee8268fSThierry Reding struct drm_fb_helper base; 35dbc33c7dSDaniel Stone struct drm_framebuffer *fb; 36dee8268fSThierry Reding }; 3760c2f709SThierry Reding #endif 38dee8268fSThierry Reding 39dee8268fSThierry Reding struct tegra_drm { 40dee8268fSThierry Reding struct drm_device *drm; 41dee8268fSThierry Reding 42df06b759SThierry Reding struct iommu_domain *domain; 43fa6661b7SThierry Reding bool use_explicit_iommu; 44347ad49dSThierry Reding struct mutex mm_lock; 45df06b759SThierry Reding struct drm_mm mm; 46df06b759SThierry Reding 47ad926015SMikko Perttunen struct { 48ad926015SMikko Perttunen struct iova_domain domain; 49ad926015SMikko Perttunen unsigned long shift; 50ad926015SMikko Perttunen unsigned long limit; 51ad926015SMikko Perttunen } carveout; 52ad926015SMikko Perttunen 53dee8268fSThierry Reding struct mutex clients_lock; 54dee8268fSThierry Reding struct list_head clients; 55dee8268fSThierry Reding 56b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION 57dee8268fSThierry Reding struct tegra_fbdev *fbdev; 5860c2f709SThierry Reding #endif 59d1f3e1e0SThierry Reding 60042c0bd7SThierry Reding unsigned int hmask, vmask; 61d1f3e1e0SThierry Reding unsigned int pitch_align; 6205d1adfeSThierry Reding unsigned int num_crtcs; 631503ca47SThierry Reding 64c4755fb9SThierry Reding struct tegra_display_hub *hub; 65dee8268fSThierry Reding }; 66dee8268fSThierry Reding 67dee8268fSThierry Reding struct tegra_drm_client; 68dee8268fSThierry Reding 69dee8268fSThierry Reding struct tegra_drm_context { 70dee8268fSThierry Reding struct tegra_drm_client *client; 71dee8268fSThierry Reding struct host1x_channel *channel; 72bdd2f9cdSThierry Reding unsigned int id; 73dee8268fSThierry Reding }; 74dee8268fSThierry Reding 75dee8268fSThierry Reding struct tegra_drm_client_ops { 76dee8268fSThierry Reding int (*open_channel)(struct tegra_drm_client *client, 77dee8268fSThierry Reding struct tegra_drm_context *context); 78dee8268fSThierry Reding void (*close_channel)(struct tegra_drm_context *context); 79c40f0f1aSThierry Reding int (*is_addr_reg)(struct device *dev, u32 class, u32 offset); 800f563a4bSDmitry Osipenko int (*is_valid_class)(u32 class); 81dee8268fSThierry Reding int (*submit)(struct tegra_drm_context *context, 82dee8268fSThierry Reding struct drm_tegra_submit *args, struct drm_device *drm, 83dee8268fSThierry Reding struct drm_file *file); 84dee8268fSThierry Reding }; 85dee8268fSThierry Reding 86c40f0f1aSThierry Reding int tegra_drm_submit(struct tegra_drm_context *context, 87c40f0f1aSThierry Reding struct drm_tegra_submit *args, struct drm_device *drm, 88c40f0f1aSThierry Reding struct drm_file *file); 89c40f0f1aSThierry Reding 90dee8268fSThierry Reding struct tegra_drm_client { 91dee8268fSThierry Reding struct host1x_client base; 92dee8268fSThierry Reding struct list_head list; 938e5d19c6SThierry Reding struct tegra_drm *drm; 94*e0f2977cSMikko Perttunen struct host1x_channel *shared_channel; 95dee8268fSThierry Reding 96*e0f2977cSMikko Perttunen /* Set by driver */ 97f3b3cfccSThierry Reding unsigned int version; 98dee8268fSThierry Reding const struct tegra_drm_client_ops *ops; 99dee8268fSThierry Reding }; 100dee8268fSThierry Reding 101dee8268fSThierry Reding static inline struct tegra_drm_client * 102dee8268fSThierry Reding host1x_to_drm_client(struct host1x_client *client) 103dee8268fSThierry Reding { 104dee8268fSThierry Reding return container_of(client, struct tegra_drm_client, base); 105dee8268fSThierry Reding } 106dee8268fSThierry Reding 107688c59afSThierry Reding int tegra_drm_register_client(struct tegra_drm *tegra, 108dee8268fSThierry Reding struct tegra_drm_client *client); 109688c59afSThierry Reding int tegra_drm_unregister_client(struct tegra_drm *tegra, 110dee8268fSThierry Reding struct tegra_drm_client *client); 1117edd7961SThierry Reding int host1x_client_iommu_attach(struct host1x_client *client); 112aacdf198SThierry Reding void host1x_client_iommu_detach(struct host1x_client *client); 113dee8268fSThierry Reding 114688c59afSThierry Reding int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); 115688c59afSThierry Reding int tegra_drm_exit(struct tegra_drm *tegra); 116dee8268fSThierry Reding 117ad926015SMikko Perttunen void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova); 118ad926015SMikko Perttunen void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt, 119ad926015SMikko Perttunen dma_addr_t iova); 120ad926015SMikko Perttunen 121fb83be88SHans Verkuil struct cec_notifier; 122fb83be88SHans Verkuil 123dee8268fSThierry Reding struct tegra_output { 124dee8268fSThierry Reding struct device_node *of_node; 125dee8268fSThierry Reding struct device *dev; 126dee8268fSThierry Reding 127f00b9dd5SDmitry Osipenko struct drm_bridge *bridge; 1289be7d864SThierry Reding struct drm_panel *panel; 129dee8268fSThierry Reding struct i2c_adapter *ddc; 130dee8268fSThierry Reding const struct edid *edid; 131f25d0a68SThierry Reding struct cec_notifier *cec; 132dee8268fSThierry Reding unsigned int hpd_irq; 133bbad6407SThierry Reding struct gpio_desc *hpd_gpio; 134dee8268fSThierry Reding 135dee8268fSThierry Reding struct drm_encoder encoder; 136dee8268fSThierry Reding struct drm_connector connector; 137dee8268fSThierry Reding }; 138dee8268fSThierry Reding 139dee8268fSThierry Reding static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) 140dee8268fSThierry Reding { 141dee8268fSThierry Reding return container_of(e, struct tegra_output, encoder); 142dee8268fSThierry Reding } 143dee8268fSThierry Reding 144dee8268fSThierry Reding static inline struct tegra_output *connector_to_output(struct drm_connector *c) 145dee8268fSThierry Reding { 146dee8268fSThierry Reding return container_of(c, struct tegra_output, connector); 147dee8268fSThierry Reding } 148dee8268fSThierry Reding 149dee8268fSThierry Reding /* from output.c */ 150688c59afSThierry Reding int tegra_output_probe(struct tegra_output *output); 151328ec69eSThierry Reding void tegra_output_remove(struct tegra_output *output); 152688c59afSThierry Reding int tegra_output_init(struct drm_device *drm, struct tegra_output *output); 153328ec69eSThierry Reding void tegra_output_exit(struct tegra_output *output); 154c57997bcSThierry Reding void tegra_output_find_possible_crtcs(struct tegra_output *output, 155c57997bcSThierry Reding struct drm_device *drm); 156fd67e9c6SThierry Reding int tegra_output_suspend(struct tegra_output *output); 157fd67e9c6SThierry Reding int tegra_output_resume(struct tegra_output *output); 158dee8268fSThierry Reding 159132085d8SThierry Reding int tegra_output_connector_get_modes(struct drm_connector *connector); 160132085d8SThierry Reding enum drm_connector_status 161132085d8SThierry Reding tegra_output_connector_detect(struct drm_connector *connector, bool force); 162132085d8SThierry Reding void tegra_output_connector_destroy(struct drm_connector *connector); 163132085d8SThierry Reding 1646b6b6042SThierry Reding /* from dpaux.c */ 1659542c237SThierry Reding struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np); 1669542c237SThierry Reding enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux); 1679542c237SThierry Reding int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output); 1689542c237SThierry Reding int drm_dp_aux_detach(struct drm_dp_aux *aux); 1699542c237SThierry Reding int drm_dp_aux_enable(struct drm_dp_aux *aux); 1709542c237SThierry Reding int drm_dp_aux_disable(struct drm_dp_aux *aux); 1716b6b6042SThierry Reding 172dee8268fSThierry Reding /* from fb.c */ 173dee8268fSThierry Reding struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, 174dee8268fSThierry Reding unsigned int index); 175db7fbdfdSThierry Reding bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer); 176c134f019SThierry Reding int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer, 177c134f019SThierry Reding struct tegra_bo_tiling *tiling); 178f9914214SThierry Reding struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, 179f9914214SThierry Reding struct drm_file *file, 1801eb83451SVille Syrjälä const struct drm_mode_fb_cmd2 *cmd); 181e2215321SThierry Reding int tegra_drm_fb_prepare(struct drm_device *drm); 1821d1e6fe9SThierry Reding void tegra_drm_fb_free(struct drm_device *drm); 183688c59afSThierry Reding int tegra_drm_fb_init(struct drm_device *drm); 184688c59afSThierry Reding void tegra_drm_fb_exit(struct drm_device *drm); 185dee8268fSThierry Reding 186c4755fb9SThierry Reding extern struct platform_driver tegra_display_hub_driver; 187dee8268fSThierry Reding extern struct platform_driver tegra_dc_driver; 188dee8268fSThierry Reding extern struct platform_driver tegra_hdmi_driver; 189473112e4SThierry Reding extern struct platform_driver tegra_dsi_driver; 1906b6b6042SThierry Reding extern struct platform_driver tegra_dpaux_driver; 191473112e4SThierry Reding extern struct platform_driver tegra_sor_driver; 192dee8268fSThierry Reding extern struct platform_driver tegra_gr2d_driver; 1935f60ed0dSThierry Reding extern struct platform_driver tegra_gr3d_driver; 1940ae797a8SArto Merilainen extern struct platform_driver tegra_vic_driver; 195dee8268fSThierry Reding 196dee8268fSThierry Reding #endif /* HOST1X_DRM_H */ 197