xref: /linux/drivers/gpu/drm/gma500/psb_intel_drv.h (revision b889fcf63cb62e7fdb7816565e28f44dbe4a76a5)
1 /*
2  * Copyright (c) 2009-2011, Intel Corporation.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16  *
17  */
18 
19 #ifndef __INTEL_DRV_H__
20 #define __INTEL_DRV_H__
21 
22 #include <linux/i2c.h>
23 #include <linux/i2c-algo-bit.h>
24 #include <drm/drm_crtc.h>
25 #include <drm/drm_crtc_helper.h>
26 #include <linux/gpio.h>
27 
28 /*
29  * Display related stuff
30  */
31 
32 /* maximum connectors per crtcs in the mode set */
33 #define INTELFB_CONN_LIMIT 4
34 
35 #define INTEL_I2C_BUS_DVO 1
36 #define INTEL_I2C_BUS_SDVO 2
37 
38 /* Intel Pipe Clone Bit */
39 #define INTEL_HDMIB_CLONE_BIT 1
40 #define INTEL_HDMIC_CLONE_BIT 2
41 #define INTEL_HDMID_CLONE_BIT 3
42 #define INTEL_HDMIE_CLONE_BIT 4
43 #define INTEL_HDMIF_CLONE_BIT 5
44 #define INTEL_SDVO_NON_TV_CLONE_BIT 6
45 #define INTEL_SDVO_TV_CLONE_BIT 7
46 #define INTEL_SDVO_LVDS_CLONE_BIT 8
47 #define INTEL_ANALOG_CLONE_BIT 9
48 #define INTEL_TV_CLONE_BIT 10
49 #define INTEL_DP_B_CLONE_BIT 11
50 #define INTEL_DP_C_CLONE_BIT 12
51 #define INTEL_DP_D_CLONE_BIT 13
52 #define INTEL_LVDS_CLONE_BIT 14
53 #define INTEL_DVO_TMDS_CLONE_BIT 15
54 #define INTEL_DVO_LVDS_CLONE_BIT 16
55 #define INTEL_EDP_CLONE_BIT 17
56 
57 /* these are outputs from the chip - integrated only
58  * external chips are via DVO or SDVO output */
59 #define INTEL_OUTPUT_UNUSED 0
60 #define INTEL_OUTPUT_ANALOG 1
61 #define INTEL_OUTPUT_DVO 2
62 #define INTEL_OUTPUT_SDVO 3
63 #define INTEL_OUTPUT_LVDS 4
64 #define INTEL_OUTPUT_TVOUT 5
65 #define INTEL_OUTPUT_HDMI 6
66 #define INTEL_OUTPUT_MIPI 7
67 #define INTEL_OUTPUT_MIPI2 8
68 #define INTEL_OUTPUT_DISPLAYPORT 9
69 #define INTEL_OUTPUT_EDP 10
70 
71 #define INTEL_DVO_CHIP_NONE 0
72 #define INTEL_DVO_CHIP_LVDS 1
73 #define INTEL_DVO_CHIP_TMDS 2
74 #define INTEL_DVO_CHIP_TVOUT 4
75 
76 #define INTEL_MODE_PIXEL_MULTIPLIER_SHIFT (0x0)
77 #define INTEL_MODE_PIXEL_MULTIPLIER_MASK (0xf << INTEL_MODE_PIXEL_MULTIPLIER_SHIFT)
78 
79 static inline void
80 psb_intel_mode_set_pixel_multiplier(struct drm_display_mode *mode,
81 				int multiplier)
82 {
83 	mode->clock *= multiplier;
84 	mode->private_flags |= multiplier;
85 }
86 
87 static inline int
88 psb_intel_mode_get_pixel_multiplier(const struct drm_display_mode *mode)
89 {
90 	return (mode->private_flags & INTEL_MODE_PIXEL_MULTIPLIER_MASK)
91 	       >> INTEL_MODE_PIXEL_MULTIPLIER_SHIFT;
92 }
93 
94 
95 /*
96  * Hold information useally put on the device driver privates here,
97  * since it needs to be shared across multiple of devices drivers privates.
98  */
99 struct psb_intel_mode_device {
100 
101 	/*
102 	 * Abstracted memory manager operations
103 	 */
104 	 size_t(*bo_offset) (struct drm_device *dev, void *bo);
105 
106 	/*
107 	 * LVDS info
108 	 */
109 	int backlight_duty_cycle;	/* restore backlight to this value */
110 	bool panel_wants_dither;
111 	struct drm_display_mode *panel_fixed_mode;
112 	struct drm_display_mode *panel_fixed_mode2;
113 	struct drm_display_mode *vbt_mode;	/* if any */
114 
115 	uint32_t saveBLC_PWM_CTL;
116 };
117 
118 struct psb_intel_i2c_chan {
119 	/* for getting at dev. private (mmio etc.) */
120 	struct drm_device *drm_dev;
121 	u32 reg;		/* GPIO reg */
122 	struct i2c_adapter adapter;
123 	struct i2c_algo_bit_data algo;
124 	u8 slave_addr;
125 };
126 
127 struct psb_intel_encoder {
128 	struct drm_encoder base;
129 	int type;
130 	bool needs_tv_clock;
131 	void (*hot_plug)(struct psb_intel_encoder *);
132 	int crtc_mask;
133 	int clone_mask;
134 	u32 ddi_select;	/* Channel info */
135 #define DDI0_SELECT	0x01
136 #define DDI1_SELECT	0x02
137 #define DP_MASK		0x8000
138 #define DDI_MASK	0x03
139 	void *dev_priv; /* For sdvo_priv, lvds_priv, etc... */
140 
141 	/* FIXME: Either make SDVO and LVDS store it's i2c here or give CDV it's
142 	   own set of output privates */
143 	struct psb_intel_i2c_chan *i2c_bus;
144 	struct psb_intel_i2c_chan *ddc_bus;
145 };
146 
147 struct psb_intel_connector {
148 	struct drm_connector base;
149 	struct psb_intel_encoder *encoder;
150 };
151 
152 struct psb_intel_crtc_state {
153 	uint32_t saveDSPCNTR;
154 	uint32_t savePIPECONF;
155 	uint32_t savePIPESRC;
156 	uint32_t saveDPLL;
157 	uint32_t saveFP0;
158 	uint32_t saveFP1;
159 	uint32_t saveHTOTAL;
160 	uint32_t saveHBLANK;
161 	uint32_t saveHSYNC;
162 	uint32_t saveVTOTAL;
163 	uint32_t saveVBLANK;
164 	uint32_t saveVSYNC;
165 	uint32_t saveDSPSTRIDE;
166 	uint32_t saveDSPSIZE;
167 	uint32_t saveDSPPOS;
168 	uint32_t saveDSPBASE;
169 	uint32_t savePalette[256];
170 };
171 
172 struct psb_intel_crtc {
173 	struct drm_crtc base;
174 	int pipe;
175 	int plane;
176 	uint32_t cursor_addr;
177 	struct gtt_range *cursor_gt;
178 	u8 lut_r[256], lut_g[256], lut_b[256];
179 	u8 lut_adj[256];
180 	struct psb_intel_framebuffer *fbdev_fb;
181 	/* a mode_set for fbdev users on this crtc */
182 	struct drm_mode_set mode_set;
183 
184 	/* GEM object that holds our cursor */
185 	struct drm_gem_object *cursor_obj;
186 
187 	struct drm_display_mode saved_mode;
188 	struct drm_display_mode saved_adjusted_mode;
189 
190 	struct psb_intel_mode_device *mode_dev;
191 
192 	/*crtc mode setting flags*/
193 	u32 mode_flags;
194 
195 	bool active;
196 
197 	/* Saved Crtc HW states */
198 	struct psb_intel_crtc_state *crtc_state;
199 };
200 
201 #define to_psb_intel_crtc(x)	\
202 		container_of(x, struct psb_intel_crtc, base)
203 #define to_psb_intel_connector(x) \
204 		container_of(x, struct psb_intel_connector, base)
205 #define to_psb_intel_encoder(x)	\
206 		container_of(x, struct psb_intel_encoder, base)
207 #define to_psb_intel_framebuffer(x)	\
208 		container_of(x, struct psb_intel_framebuffer, base)
209 
210 struct psb_intel_i2c_chan *psb_intel_i2c_create(struct drm_device *dev,
211 					const u32 reg, const char *name);
212 void psb_intel_i2c_destroy(struct psb_intel_i2c_chan *chan);
213 int psb_intel_ddc_get_modes(struct drm_connector *connector,
214 			    struct i2c_adapter *adapter);
215 extern bool psb_intel_ddc_probe(struct i2c_adapter *adapter);
216 
217 extern void psb_intel_crtc_init(struct drm_device *dev, int pipe,
218 			    struct psb_intel_mode_device *mode_dev);
219 extern void psb_intel_crt_init(struct drm_device *dev);
220 extern bool psb_intel_sdvo_init(struct drm_device *dev, int output_device);
221 extern void psb_intel_dvo_init(struct drm_device *dev);
222 extern void psb_intel_tv_init(struct drm_device *dev);
223 extern void psb_intel_lvds_init(struct drm_device *dev,
224 			    struct psb_intel_mode_device *mode_dev);
225 extern void psb_intel_lvds_set_brightness(struct drm_device *dev, int level);
226 extern void oaktrail_lvds_init(struct drm_device *dev,
227 			   struct psb_intel_mode_device *mode_dev);
228 extern void oaktrail_wait_for_INTR_PKT_SENT(struct drm_device *dev);
229 extern void oaktrail_dsi_init(struct drm_device *dev,
230 			   struct psb_intel_mode_device *mode_dev);
231 extern void mid_dsi_init(struct drm_device *dev,
232 		    struct psb_intel_mode_device *mode_dev, int dsi_num);
233 
234 extern void psb_intel_crtc_load_lut(struct drm_crtc *crtc);
235 extern void psb_intel_encoder_prepare(struct drm_encoder *encoder);
236 extern void psb_intel_encoder_commit(struct drm_encoder *encoder);
237 extern void psb_intel_encoder_destroy(struct drm_encoder *encoder);
238 
239 static inline struct psb_intel_encoder *psb_intel_attached_encoder(
240 						struct drm_connector *connector)
241 {
242 	return to_psb_intel_connector(connector)->encoder;
243 }
244 
245 extern void psb_intel_connector_attach_encoder(
246 					struct psb_intel_connector *connector,
247 					struct psb_intel_encoder *encoder);
248 
249 extern struct drm_encoder *psb_intel_best_encoder(struct drm_connector
250 					      *connector);
251 
252 extern struct drm_display_mode *psb_intel_crtc_mode_get(struct drm_device *dev,
253 						    struct drm_crtc *crtc);
254 extern void psb_intel_wait_for_vblank(struct drm_device *dev);
255 extern int psb_intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
256 				struct drm_file *file_priv);
257 extern struct drm_crtc *psb_intel_get_crtc_from_pipe(struct drm_device *dev,
258 						 int pipe);
259 extern struct drm_connector *psb_intel_sdvo_find(struct drm_device *dev,
260 					     int sdvoB);
261 extern int psb_intel_sdvo_supports_hotplug(struct drm_connector *connector);
262 extern void psb_intel_sdvo_set_hotplug(struct drm_connector *connector,
263 				   int enable);
264 extern int intelfb_probe(struct drm_device *dev);
265 extern int intelfb_remove(struct drm_device *dev,
266 			  struct drm_framebuffer *fb);
267 extern struct drm_framebuffer *psb_intel_framebuffer_create(struct drm_device
268 							*dev, struct
269 							drm_mode_fb_cmd
270 							*mode_cmd,
271 							void *mm_private);
272 extern bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder,
273 				      const struct drm_display_mode *mode,
274 				      struct drm_display_mode *adjusted_mode);
275 extern int psb_intel_lvds_mode_valid(struct drm_connector *connector,
276 				     struct drm_display_mode *mode);
277 extern int psb_intel_lvds_set_property(struct drm_connector *connector,
278 					struct drm_property *property,
279 					uint64_t value);
280 extern void psb_intel_lvds_destroy(struct drm_connector *connector);
281 extern const struct drm_encoder_funcs psb_intel_lvds_enc_funcs;
282 
283 /* intel_gmbus.c */
284 extern void gma_intel_i2c_reset(struct drm_device *dev);
285 extern int gma_intel_setup_gmbus(struct drm_device *dev);
286 extern void gma_intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
287 extern void gma_intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
288 extern void gma_intel_teardown_gmbus(struct drm_device *dev);
289 
290 /* DP support */
291 extern void cdv_intel_dp_init(struct drm_device *dev, struct psb_intel_mode_device *mode_dev, int output_reg);
292 extern void cdv_intel_dp_set_m_n(struct drm_crtc *crtc,
293 					struct drm_display_mode *mode,
294 					struct drm_display_mode *adjusted_mode);
295 
296 extern void psb_intel_attach_force_audio_property(struct drm_connector *connector);
297 extern void psb_intel_attach_broadcast_rgb_property(struct drm_connector *connector);
298 
299 extern int cdv_sb_read(struct drm_device *dev, u32 reg, u32 *val);
300 extern int cdv_sb_write(struct drm_device *dev, u32 reg, u32 val);
301 extern void cdv_sb_reset(struct drm_device *dev);
302 
303 extern void cdv_intel_attach_force_audio_property(struct drm_connector *connector);
304 extern void cdv_intel_attach_broadcast_rgb_property(struct drm_connector *connector);
305 
306 #endif				/* __INTEL_DRV_H__ */
307