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