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