drm.h revision 894752bb576a26d3343cf8c674b73899f948da68
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 21struct 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; 37}; 38 39struct host1x_client; 40 41struct 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 46struct 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 55extern int host1x_drm_init(struct host1x *host1x, struct drm_device *drm); 56extern int host1x_drm_exit(struct host1x *host1x); 57 58extern int host1x_register_client(struct host1x *host1x, 59 struct host1x_client *client); 60extern int host1x_unregister_client(struct host1x *host1x, 61 struct host1x_client *client); 62 63struct tegra_output; 64 65struct 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 88static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client) 89{ 90 return container_of(client, struct tegra_dc, client); 91} 92 93static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc) 94{ 95 return container_of(crtc, struct tegra_dc, base); 96} 97 98static 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 104static inline unsigned long tegra_dc_readl(struct tegra_dc *dc, 105 unsigned long reg) 106{ 107 return readl(dc->regs + (reg << 2)); 108} 109 110struct tegra_output_ops { 111 int (*enable)(struct tegra_output *output); 112 int (*disable)(struct tegra_output *output); 113 int (*setup_clock)(struct tegra_output *output, struct clk *clk, 114 unsigned long pclk); 115 int (*check_mode)(struct tegra_output *output, 116 struct drm_display_mode *mode, 117 enum drm_mode_status *status); 118}; 119 120enum tegra_output_type { 121 TEGRA_OUTPUT_RGB, 122 TEGRA_OUTPUT_HDMI, 123}; 124 125struct tegra_output { 126 struct device_node *of_node; 127 struct device *dev; 128 129 const struct tegra_output_ops *ops; 130 enum tegra_output_type type; 131 132 struct i2c_adapter *ddc; 133 const struct edid *edid; 134 unsigned int hpd_irq; 135 int hpd_gpio; 136 137 struct drm_encoder encoder; 138 struct drm_connector connector; 139}; 140 141static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) 142{ 143 return container_of(e, struct tegra_output, encoder); 144} 145 146static inline struct tegra_output *connector_to_output(struct drm_connector *c) 147{ 148 return container_of(c, struct tegra_output, connector); 149} 150 151static inline int tegra_output_enable(struct tegra_output *output) 152{ 153 if (output && output->ops && output->ops->enable) 154 return output->ops->enable(output); 155 156 return output ? -ENOSYS : -EINVAL; 157} 158 159static inline int tegra_output_disable(struct tegra_output *output) 160{ 161 if (output && output->ops && output->ops->disable) 162 return output->ops->disable(output); 163 164 return output ? -ENOSYS : -EINVAL; 165} 166 167static inline int tegra_output_setup_clock(struct tegra_output *output, 168 struct clk *clk, unsigned long pclk) 169{ 170 if (output && output->ops && output->ops->setup_clock) 171 return output->ops->setup_clock(output, clk, pclk); 172 173 return output ? -ENOSYS : -EINVAL; 174} 175 176static inline int tegra_output_check_mode(struct tegra_output *output, 177 struct drm_display_mode *mode, 178 enum drm_mode_status *status) 179{ 180 if (output && output->ops && output->ops->check_mode) 181 return output->ops->check_mode(output, mode, status); 182 183 return output ? -ENOSYS : -EINVAL; 184} 185 186/* from rgb.c */ 187extern int tegra_dc_rgb_probe(struct tegra_dc *dc); 188extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc); 189extern int tegra_dc_rgb_exit(struct tegra_dc *dc); 190 191/* from output.c */ 192extern int tegra_output_parse_dt(struct tegra_output *output); 193extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output); 194extern int tegra_output_exit(struct tegra_output *output); 195 196/* from fb.c */ 197extern int tegra_drm_fb_init(struct drm_device *drm); 198extern void tegra_drm_fb_exit(struct drm_device *drm); 199 200extern struct platform_driver tegra_host1x_driver; 201extern struct platform_driver tegra_hdmi_driver; 202extern struct platform_driver tegra_dc_driver; 203extern struct drm_driver tegra_drm_driver; 204 205#endif /* TEGRA_DRM_H */ 206