blob: 29911eff9cebd047cd844d9d7a645833cdfbd6e8 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00002/*
3 * Copyright (C) 2012 Avionic Design GmbH
Terje Bergstromd43f81c2013-03-22 16:34:09 +02004 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00005 */
6
Terje Bergstrom4231c6b2013-03-22 16:34:05 +02007#ifndef HOST1X_DRM_H
8#define HOST1X_DRM_H 1
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00009
Thierry Redinge1e90642013-09-24 13:59:01 +020010#include <linux/host1x.h>
Mikko Perttunenad926012016-12-14 13:16:11 +020011#include <linux/iova.h>
Thierry Redingfb36d0ee2015-04-27 15:12:39 +020012#include <linux/of_gpio.h>
Thierry Redinge1e90642013-09-24 13:59:01 +020013
Thierry Redingc4755fb2017-11-13 11:08:13 +010014#include <drm/drm_atomic.h>
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000015#include <drm/drm_edid.h>
Laurent Pinchart93382032016-11-28 20:51:09 +020016#include <drm/drm_encoder.h>
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000017#include <drm/drm_fb_helper.h>
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000018#include <drm/drm_fixed.h>
Daniel Vetterfcd70cd2019-01-17 22:03:34 +010019#include <drm/drm_probe_helper.h>
Sam Ravnborgeb1df692019-08-04 11:41:30 +020020#include <uapi/drm/tegra_drm.h>
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000021
Thierry Redingc134f012014-06-03 14:48:12 +020022#include "gem.h"
Thierry Redingc4755fb2017-11-13 11:08:13 +010023#include "hub.h"
Thierry Reding67e04d12017-08-15 15:41:10 +020024#include "trace.h"
Thierry Redingc134f012014-06-03 14:48:12 +020025
Stephen Warrenca480802013-11-06 16:20:54 -070026struct reset_control;
27
Archit Tanejab110ef32015-10-27 13:40:59 +053028#ifdef CONFIG_DRM_FBDEV_EMULATION
Arto Merilainende2ba662013-03-22 16:34:08 +020029struct tegra_fbdev {
30 struct drm_fb_helper base;
Daniel Stonedbc33c72018-03-30 15:11:27 +010031 struct drm_framebuffer *fb;
Arto Merilainende2ba662013-03-22 16:34:08 +020032};
Thierry Reding60c2f702013-10-31 13:28:50 +010033#endif
Arto Merilainende2ba662013-03-22 16:34:08 +020034
Thierry Reding386a2a72013-09-24 13:22:17 +020035struct tegra_drm {
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000036 struct drm_device *drm;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000037
Thierry Redingdf06b752014-06-26 21:41:53 +020038 struct iommu_domain *domain;
Thierry Redingbc8828b2017-10-12 17:43:33 +020039 struct iommu_group *group;
Thierry Reding347ad49d2017-03-09 20:04:56 +010040 struct mutex mm_lock;
Thierry Redingdf06b752014-06-26 21:41:53 +020041 struct drm_mm mm;
42
Mikko Perttunenad926012016-12-14 13:16:11 +020043 struct {
44 struct iova_domain domain;
45 unsigned long shift;
46 unsigned long limit;
47 } carveout;
48
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000049 struct mutex clients_lock;
50 struct list_head clients;
51
Archit Tanejab110ef32015-10-27 13:40:59 +053052#ifdef CONFIG_DRM_FBDEV_EMULATION
Arto Merilainende2ba662013-03-22 16:34:08 +020053 struct tegra_fbdev *fbdev;
Thierry Reding60c2f702013-10-31 13:28:50 +010054#endif
Thierry Redingd1f3e1e2014-07-11 08:29:14 +020055
56 unsigned int pitch_align;
Thierry Reding1503ca42014-11-24 17:41:23 +010057
Thierry Redingc4755fb2017-11-13 11:08:13 +010058 struct tegra_display_hub *hub;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000059};
60
Thierry Reding53fa7f72013-09-24 15:35:40 +020061struct tegra_drm_client;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000062
Thierry Redingc88c3632013-09-26 16:08:22 +020063struct tegra_drm_context {
Thierry Reding53fa7f72013-09-24 15:35:40 +020064 struct tegra_drm_client *client;
Terje Bergstromd43f81c2013-03-22 16:34:09 +020065 struct host1x_channel *channel;
Thierry Redingbdd2f9c2017-03-09 20:04:55 +010066 unsigned int id;
Terje Bergstromd43f81c2013-03-22 16:34:09 +020067};
68
Thierry Reding53fa7f72013-09-24 15:35:40 +020069struct tegra_drm_client_ops {
70 int (*open_channel)(struct tegra_drm_client *client,
Thierry Redingc88c3632013-09-26 16:08:22 +020071 struct tegra_drm_context *context);
72 void (*close_channel)(struct tegra_drm_context *context);
Thierry Redingc40f0f12013-10-10 11:00:33 +020073 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
Dmitry Osipenko0f563a42017-06-15 02:18:37 +030074 int (*is_valid_class)(u32 class);
Thierry Redingc88c3632013-09-26 16:08:22 +020075 int (*submit)(struct tegra_drm_context *context,
Terje Bergstromd43f81c2013-03-22 16:34:09 +020076 struct drm_tegra_submit *args, struct drm_device *drm,
77 struct drm_file *file);
78};
79
Thierry Redingc40f0f12013-10-10 11:00:33 +020080int 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 Reding53fa7f72013-09-24 15:35:40 +020084struct tegra_drm_client {
85 struct host1x_client base;
Thierry Reding776dc382013-10-14 14:43:22 +020086 struct list_head list;
Thierry Reding8e5d19c2019-02-01 14:28:31 +010087 struct tegra_drm *drm;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000088
Thierry Redingf3b3cfc2018-05-16 17:05:04 +020089 unsigned int version;
Thierry Reding53fa7f72013-09-24 15:35:40 +020090 const struct tegra_drm_client_ops *ops;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000091};
92
Thierry Reding53fa7f72013-09-24 15:35:40 +020093static inline struct tegra_drm_client *
Thierry Reding776dc382013-10-14 14:43:22 +020094host1x_to_drm_client(struct host1x_client *client)
Thierry Reding53fa7f72013-09-24 15:35:40 +020095{
96 return container_of(client, struct tegra_drm_client, base);
97}
98
Thierry Reding688c59a2014-04-16 09:54:21 +020099int tegra_drm_register_client(struct tegra_drm *tegra,
100 struct tegra_drm_client *client);
101int tegra_drm_unregister_client(struct tegra_drm *tegra,
102 struct tegra_drm_client *client);
Thierry Reding0c407de2018-05-04 15:02:24 +0200103struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client,
104 bool shared);
105void host1x_client_iommu_detach(struct host1x_client *client,
106 struct iommu_group *group);
Thierry Reding776dc382013-10-14 14:43:22 +0200107
Thierry Reding688c59a2014-04-16 09:54:21 +0200108int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
109int tegra_drm_exit(struct tegra_drm *tegra);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000110
Mikko Perttunenad926012016-12-14 13:16:11 +0200111void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
112void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
113 dma_addr_t iova);
114
Hans Verkuilfb83be82017-09-11 14:29:52 +0200115struct cec_notifier;
116
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000117struct tegra_output {
118 struct device_node *of_node;
119 struct device *dev;
120
Thierry Reding9be7d862013-08-30 15:22:36 +0200121 struct drm_panel *panel;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000122 struct i2c_adapter *ddc;
123 const struct edid *edid;
Thierry Redingf25d0a62018-12-10 17:34:54 +0100124 struct cec_notifier *cec;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000125 unsigned int hpd_irq;
Thierry Redingbbad6402019-06-05 10:46:46 +0200126 struct gpio_desc *hpd_gpio;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000127
128 struct drm_encoder encoder;
129 struct drm_connector connector;
130};
131
132static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
133{
134 return container_of(e, struct tegra_output, encoder);
135}
136
137static inline struct tegra_output *connector_to_output(struct drm_connector *c)
138{
139 return container_of(c, struct tegra_output, connector);
140}
141
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000142/* from output.c */
Thierry Reding688c59a2014-04-16 09:54:21 +0200143int tegra_output_probe(struct tegra_output *output);
Thierry Reding328ec692014-12-19 15:55:08 +0100144void tegra_output_remove(struct tegra_output *output);
Thierry Reding688c59a2014-04-16 09:54:21 +0200145int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
Thierry Reding328ec692014-12-19 15:55:08 +0100146void tegra_output_exit(struct tegra_output *output);
Thierry Redingc57997b2017-10-12 19:12:57 +0200147void tegra_output_find_possible_crtcs(struct tegra_output *output,
148 struct drm_device *drm);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000149
Thierry Reding132085d2014-11-28 15:38:40 +0100150int tegra_output_connector_get_modes(struct drm_connector *connector);
Thierry Reding132085d2014-11-28 15:38:40 +0100151enum drm_connector_status
152tegra_output_connector_detect(struct drm_connector *connector, bool force);
153void tegra_output_connector_destroy(struct drm_connector *connector);
154
155void tegra_output_encoder_destroy(struct drm_encoder *encoder);
156
Thierry Reding6b6b6042013-11-15 16:06:05 +0100157/* from dpaux.c */
Thierry Reding6b6b6042013-11-15 16:06:05 +0100158struct drm_dp_link;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100159
Thierry Reding9542c232015-07-08 13:39:09 +0200160struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
161enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
162int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
163int drm_dp_aux_detach(struct drm_dp_aux *aux);
164int drm_dp_aux_enable(struct drm_dp_aux *aux);
165int drm_dp_aux_disable(struct drm_dp_aux *aux);
166int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding);
167int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link,
168 u8 pattern);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100169
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000170/* from fb.c */
Arto Merilainende2ba662013-03-22 16:34:08 +0200171struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
172 unsigned int index);
Thierry Redingdb7fbdf2013-10-07 09:47:58 +0200173bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
Thierry Redingc134f012014-06-03 14:48:12 +0200174int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
175 struct tegra_bo_tiling *tiling);
Thierry Redingf9914212014-11-26 13:03:57 +0100176struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
177 struct drm_file *file,
Ville Syrjälä1eb834512015-11-11 19:11:29 +0200178 const struct drm_mode_fb_cmd2 *cmd);
Thierry Redinge2215321f2014-06-27 17:19:25 +0200179int tegra_drm_fb_prepare(struct drm_device *drm);
Thierry Reding1d1e6fe2014-11-06 14:12:08 +0100180void tegra_drm_fb_free(struct drm_device *drm);
Thierry Reding688c59a2014-04-16 09:54:21 +0200181int tegra_drm_fb_init(struct drm_device *drm);
182void tegra_drm_fb_exit(struct drm_device *drm);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000183
Thierry Redingc4755fb2017-11-13 11:08:13 +0100184extern struct platform_driver tegra_display_hub_driver;
Thierry Reding776dc382013-10-14 14:43:22 +0200185extern struct platform_driver tegra_dc_driver;
186extern struct platform_driver tegra_hdmi_driver;
Thierry Reding473112e2015-09-10 16:07:14 +0200187extern struct platform_driver tegra_dsi_driver;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100188extern struct platform_driver tegra_dpaux_driver;
Thierry Reding473112e2015-09-10 16:07:14 +0200189extern struct platform_driver tegra_sor_driver;
Thierry Reding776dc382013-10-14 14:43:22 +0200190extern struct platform_driver tegra_gr2d_driver;
Thierry Reding5f60ed02013-02-28 08:08:01 +0100191extern struct platform_driver tegra_gr3d_driver;
Arto Merilainen0ae797a2016-12-14 13:16:13 +0200192extern struct platform_driver tegra_vic_driver;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000193
Terje Bergstrom4231c6b2013-03-22 16:34:05 +0200194#endif /* HOST1X_DRM_H */