1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 Texas Instruments
4  * Author: Rob Clark <robdclark@gmail.com>
5  */
6 
7 #ifndef __TILCDC_DRV_H__
8 #define __TILCDC_DRV_H__
9 
10 #include <linux/cpufreq.h>
11 #include <linux/irqreturn.h>
12 
13 #include <drm/drm_print.h>
14 
15 struct clk;
16 struct workqueue_struct;
17 
18 struct drm_connector;
19 struct drm_connector_helper_funcs;
20 struct drm_crtc;
21 struct drm_device;
22 struct drm_display_mode;
23 struct drm_encoder;
24 struct drm_framebuffer;
25 struct drm_minor;
26 struct drm_pending_vblank_event;
27 struct drm_plane;
28 
29 /* Defaulting to pixel clock defined on AM335x */
30 #define TILCDC_DEFAULT_MAX_PIXELCLOCK  126000
31 /* Defaulting to max width as defined on AM335x */
32 #define TILCDC_DEFAULT_MAX_WIDTH  2048
33 /*
34  * This may need some tweaking, but want to allow at least 1280x1024@60
35  * with optimized DDR & EMIF settings tweaked 1920x1080@24 appears to
36  * be supportable
37  */
38 #define TILCDC_DEFAULT_MAX_BANDWIDTH  (1280*1024*60)
39 
40 
41 struct tilcdc_drm_private {
42 	void __iomem *mmio;
43 
44 	struct clk *clk;         /* functional clock */
45 	int rev;                 /* IP revision */
46 
47 	/* don't attempt resolutions w/ higher W * H * Hz: */
48 	uint32_t max_bandwidth;
49 	/*
50 	 * Pixel Clock will be restricted to some value as
51 	 * defined in the device datasheet measured in KHz
52 	 */
53 	uint32_t max_pixelclock;
54 	/*
55 	 * Max allowable width is limited on a per device basis
56 	 * measured in pixels
57 	 */
58 	uint32_t max_width;
59 
60 	/* Supported pixel formats */
61 	const uint32_t *pixelformats;
62 	uint32_t num_pixelformats;
63 
64 #ifdef CONFIG_CPU_FREQ
65 	struct notifier_block freq_transition;
66 #endif
67 
68 	struct workqueue_struct *wq;
69 
70 	struct drm_crtc *crtc;
71 
72 	unsigned int num_encoders;
73 	struct drm_encoder *encoders[8];
74 
75 	unsigned int num_connectors;
76 	struct drm_connector *connectors[8];
77 
78 	struct drm_encoder *external_encoder;
79 	struct drm_connector *external_connector;
80 	const struct drm_connector_helper_funcs *connector_funcs;
81 
82 	bool is_registered;
83 	bool is_componentized;
84 };
85 
86 /* Sub-module for display.  Since we don't know at compile time what panels
87  * or display adapter(s) might be present (for ex, off chip dvi/tfp410,
88  * hdmi encoder, various lcd panels), the connector/encoder(s) are split into
89  * separate drivers.  If they are probed and found to be present, they
90  * register themselves with tilcdc_register_module().
91  */
92 struct tilcdc_module;
93 
94 struct tilcdc_module_ops {
95 	/* create appropriate encoders/connectors: */
96 	int (*modeset_init)(struct tilcdc_module *mod, struct drm_device *dev);
97 #ifdef CONFIG_DEBUG_FS
98 	/* create debugfs nodes (can be NULL): */
99 	int (*debugfs_init)(struct tilcdc_module *mod, struct drm_minor *minor);
100 #endif
101 };
102 
103 struct tilcdc_module {
104 	const char *name;
105 	struct list_head list;
106 	const struct tilcdc_module_ops *funcs;
107 };
108 
109 void tilcdc_module_init(struct tilcdc_module *mod, const char *name,
110 		const struct tilcdc_module_ops *funcs);
111 void tilcdc_module_cleanup(struct tilcdc_module *mod);
112 
113 /* Panel config that needs to be set in the crtc, but is not coming from
114  * the mode timings.  The display module is expected to call
115  * tilcdc_crtc_set_panel_info() to set this during modeset.
116  */
117 struct tilcdc_panel_info {
118 
119 	/* AC Bias Pin Frequency */
120 	uint32_t ac_bias;
121 
122 	/* AC Bias Pin Transitions per Interrupt */
123 	uint32_t ac_bias_intrpt;
124 
125 	/* DMA burst size */
126 	uint32_t dma_burst_sz;
127 
128 	/* Bits per pixel */
129 	uint32_t bpp;
130 
131 	/* FIFO DMA Request Delay */
132 	uint32_t fdd;
133 
134 	/* TFT Alternative Signal Mapping (Only for active) */
135 	bool tft_alt_mode;
136 
137 	/* Invert pixel clock */
138 	bool invert_pxl_clk;
139 
140 	/* Horizontal and Vertical Sync Edge: 0=rising 1=falling */
141 	uint32_t sync_edge;
142 
143 	/* Horizontal and Vertical Sync: Control: 0=ignore */
144 	uint32_t sync_ctrl;
145 
146 	/* Raster Data Order Select: 1=Most-to-least 0=Least-to-most */
147 	uint32_t raster_order;
148 
149 	/* DMA FIFO threshold */
150 	uint32_t fifo_th;
151 };
152 
153 #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
154 
155 int tilcdc_crtc_create(struct drm_device *dev);
156 irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc);
157 void tilcdc_crtc_update_clk(struct drm_crtc *crtc);
158 void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc,
159 		const struct tilcdc_panel_info *info);
160 void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc,
161 					bool simulate_vesa_sync);
162 int tilcdc_crtc_mode_valid(struct drm_crtc *crtc, struct drm_display_mode *mode);
163 int tilcdc_crtc_max_width(struct drm_crtc *crtc);
164 void tilcdc_crtc_shutdown(struct drm_crtc *crtc);
165 int tilcdc_crtc_update_fb(struct drm_crtc *crtc,
166 		struct drm_framebuffer *fb,
167 		struct drm_pending_vblank_event *event);
168 
169 int tilcdc_plane_init(struct drm_device *dev, struct drm_plane *plane);
170 
171 #endif /* __TILCDC_DRV_H__ */
172