blob: e8940a3b98b5ea7af851e93ab5efbd7c75ec1b7f [file] [log] [blame]
Ronald G. Minnich99451b12013-06-27 10:42:59 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2012 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <drivers/intel/gma/i915_reg.h>
21#include <drivers/intel/gma/drm_dp_helper.h>
22#include <edid.h>
23
24/* port types. We stick with the same defines as the kernel */
25#define INTEL_OUTPUT_UNUSED 0
26#define INTEL_OUTPUT_ANALOG 1
27#define INTEL_OUTPUT_DVO 2
28#define INTEL_OUTPUT_SDVO 3
29#define INTEL_OUTPUT_LVDS 4
30#define INTEL_OUTPUT_TVOUT 5
31#define INTEL_OUTPUT_HDMI 6
32#define INTEL_OUTPUT_DISPLAYPORT 7
33#define INTEL_OUTPUT_EDP 8
34
35/* things that are, strangely, not defined anywhere? */
36#define PCH_PP_UNLOCK 0xabcd0000
37#define WMx_LP_SR_EN (1<<31)
38#define PRB0_TAIL 0x02030
39#define PRB0_HEAD 0x02034
40#define PRB0_START 0x02038
41#define PRB0_CTL 0x0203c
42
Furquan Shaikhd0a81f72013-07-30 12:41:08 -070043enum port {
44 PORT_A = 0,
45 PORT_B,
46 PORT_C,
47 PORT_D,
48 PORT_E,
49 I915_NUM_PORTS
50};
51
52enum pipe {
53 PIPE_A = 0,
54 PIPE_B,
55 PIPE_C,
56 I915_NUM_PIPES
57};
58
Furquan Shaikhdb3157c2013-07-31 16:47:31 -070059enum transcoder {
60 TRANSCODER_A = 0,
61 TRANSCODER_B,
62 TRANSCODER_C,
63 TRANSCODER_EDP = 0xF,
64};
65
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070066enum plane {
67 PLANE_A = 0,
68 PLANE_B,
69 PLANE_C,
70};
71
Ronald G. Minnich99451b12013-06-27 10:42:59 -070072/* debug enums. These are for printks that, due to their place in the
73 * middle of graphics device IO, might change timing. Use with care
74 * or not at all.
75 */
76enum {
77 vio = 2, /* dump every IO */
78 vspin = 4, /* print # of times we spun on a register value */
79};
80
81/* The mainboard must provide these functions. */
82unsigned long io_i915_read32(unsigned long addr);
83void io_i915_write32(unsigned long val, unsigned long addr);
84
85/*
86 * To communicate to and control the extracted-from-kernel code,
87 * we need this struct. It has a counterpart in the ARM code, so
88 * there is a precedent.
89 */
90
91#define DP_RECEIVER_CAP_SIZE 0xf
92#define DP_LINK_STATUS_SIZE 6
93#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
94
95#define DP_LINK_CONFIGURATION_SIZE 9
96
Furquan Shaikh6b190712013-07-22 16:18:31 -070097struct intel_dp_m_n {
98 uint32_t tu;
99 uint32_t gmch_m;
100 uint32_t gmch_n;
101 uint32_t link_m;
102 uint32_t link_n;
103};
104
Ronald G. Minnich99451b12013-06-27 10:42:59 -0700105struct intel_dp {
106 int gen; // 6 for link, 7 for wtm2
107 int has_pch_split; // 1 for link and wtm2
108 int has_pch_cpt; // 1 for everything we know about.
109 int is_haswell;
110 /* output register offset in MMIO space. Usually DP_A */
111 u32 output_reg;
112 /* The initial value of the DP register.
113 * Mainboards can set this to a non-zero
114 * value in the case that there are undetectable
115 * but essential parameters.
116 */
117 u32 DP;
118 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE];
119 u32 color_range;
120 /* these paramaters are determined after reading the DPCD */
121 int dpms_mode;
122 uint8_t link_bw;
123 uint8_t lane_count;
124 /* This data is read from the panel via the AUX channel.*/
125 uint8_t dpcd[DP_RECEIVER_CAP_SIZE];
126 int type;
127 int edp;
128 int is_pch_edp;
129 /* state related to training. */
130 uint8_t train_set[4];
131 /* Determined from EDID or coreboot hard-sets. */
132 int panel_power_up_delay;
133 int panel_power_down_delay;
134 int panel_power_cycle_delay;
135 int backlight_on_delay;
136 int backlight_off_delay;
137 int want_panel_vdd;
138 u32 clock;
139 int port;
140 int pipe;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700141 int plane;
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700142 int pipe_bits_per_pixel;
Ronald G. Minnich99451b12013-06-27 10:42:59 -0700143 /* i2c on aux is ... interesting.
144 * Before you do an i2c cycle, you need to set the address.
145 * This requires we remember it from one moment to the next.
146 * Remember it here.
147 */
148 u16 address;
149 /* timing parameters for aux channel IO. They used to compute these on
150 * each and every entry to the functions, which is kind of stupid, and it had
151 * errors anyway.
152 * note: you can get these from watching YABEL output. E.g.:
153 * you see an outb of 0x802300e1 to 64010. the 3 is the precharge
154 * and the e1 is the clock divider.
155 */
156 u32 aux_clock_divider;
157 u32 precharge;
158 /* EDID, raw and processed */
159 u8 rawedid[256];
160 int edidlen;
161 struct edid edid;
162 /* computed values needed for "i915" registers */
163 int bytes_per_pixel;
164 u32 htotal;
165 u32 hblank;
166 u32 hsync;
167 u32 vtotal;
168 u32 vblank;
169 u32 vsync;
170 u32 pfa_sz;
171 u32 pfa_pos;
172 u32 pfa_ctl;
173 u32 pipesrc;
174 u32 stride;
Furquan Shaikh6b190712013-07-22 16:18:31 -0700175 struct intel_dp_m_n m_n;
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700176 u32 flags;
Furquan Shaikhdb3157c2013-07-31 16:47:31 -0700177 u32 transcoder;
Ronald G. Minnich99451b12013-06-27 10:42:59 -0700178};
179
180/* we may yet need these. */
181void intel_dp_mode_set(struct intel_dp *intel_dp);
182void intel_dp_start_link_train(struct intel_dp *intel_dp);
183void intel_dp_complete_link_train(struct intel_dp *intel_dp);
184void intel_dp_link_down(struct intel_dp *intel_dp);
185
186int intel_dp_i2c_init(struct intel_dp *intel_dp);
187int intel_dp_i2c_aux_ch(struct intel_dp *intel_dp,
188 int mode, uint8_t write_byte, uint8_t *read_byte);
189void
190intel_dp_dpms(struct intel_dp *intel_dp, int mode);
191
192int intel_dp_get_dpcd(struct intel_dp *intel_dp);
193struct edid *intel_dp_get_edid(struct intel_dp *intel_dp);
194
195void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode);
196void ironlake_edp_pll_on(void);
197void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp);
198void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, int sync);
199int intel_dp_get_max_downspread(struct intel_dp *intel_dp, u8 *max_downspread);
200void ironlake_edp_panel_on(struct intel_dp *intel_dp);
201void ironlake_edp_backlight_on(struct intel_dp *intel_dp);
202/* needed only on haswell. */
Ronald G. Minnich99451b12013-06-27 10:42:59 -0700203void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp, int port);
204int intel_dp_aux_ch(struct intel_dp *intel_dp,
205 uint8_t *send, int send_bytes,
206 uint8_t *recv, int recv_size);
207void unpack_aux(u32 src, uint8_t *dst, int dst_bytes);
208
209
210/* drm_dp_helper.c */
211int drm_dp_channel_eq_ok(u8 link_status[DP_LINK_STATUS_SIZE],
212 int lane_count);
213int drm_dp_clock_recovery_ok(u8 link_status[DP_LINK_STATUS_SIZE],
214 int lane_count);
215u8 drm_dp_get_adjust_request_voltage(u8 link_status[DP_LINK_STATUS_SIZE],
216 int lane);
217u8 drm_dp_get_adjust_request_pre_emphasis(u8 link_status[DP_LINK_STATUS_SIZE],
218 int lane);
219
220
Ronald G. Minnich45df5962013-07-08 14:02:57 -0700221void intel_dp_wait_reg(unsigned long addr,
222 unsigned long val);
223
224void intel_dp_wait_panel_power_control(unsigned long val);
225
Furquan Shaikh6b190712013-07-22 16:18:31 -0700226void intel_dp_compute_m_n(unsigned int bits_per_pixel,
227 unsigned int nlanes,
228 unsigned int pixel_clock,
229 unsigned int link_clock,
230 struct intel_dp_m_n *m_n);
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700231
232u32 intel_ddi_calc_transcoder_flags(u32 pipe_bpp,
233 enum port port,
234 enum pipe pipe,
235 int type,
236 int lane_count,
Furquan Shaikh771c3ac2013-08-01 13:58:17 -0700237 int pf_sz,
238 u8 phsync,
239 u8 pvsync);
Furquan Shaikhdb3157c2013-07-31 16:47:31 -0700240
241enum transcoder intel_ddi_get_transcoder(enum port port,
242 enum pipe pipe);
243
244void intel_dp_set_m_n_regs(struct intel_dp *intel_dp);
245void intel_dp_set_resolution(struct intel_dp *intel_dp);
Furquan Shaikh997be3d2013-07-31 13:17:30 -0700246
247int intel_dp_i2c_write(struct intel_dp *intel_dp,
248 u8 val);
249
250int intel_dp_i2c_read(struct intel_dp *intel_dp,
251 u8 *val);
252
253int intel_dp_set_bw(struct intel_dp *intel_dp);
254int intel_dp_set_lane_count(struct intel_dp *intel_dp);
255int intel_dp_set_training_lane0(struct intel_dp *intel_dp,
256 u8 val);
257int intel_dp_set_training_pattern(struct intel_dp *intel_dp,
258 u8 pat);
259
260int intel_dp_get_link_status(struct intel_dp *intel_dp,
261 uint8_t link_status[DP_LINK_STATUS_SIZE]);
262
263int intel_dp_get_training_pattern(struct intel_dp *intel_dp,
264 u8 *recv);
265
266int intel_dp_get_lane_count(struct intel_dp *intel_dp,
267 u8 *recv);
268
269int intel_dp_get_lane_align_status(struct intel_dp *intel_dp,
270 u8 *recv);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700271
272void intel_prepare_ddi(void);
273void intel_ddi_set_pipe_settings(struct intel_dp *intel_dp);
274
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700275int gtt_poll(u32 reg, u32 mask, u32 value);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700276void gtt_write(u32 reg, u32 data);
277u32 gtt_read(u32 reg);
278
279int i915lightup(unsigned int physbase, unsigned int mmio,
280 unsigned int gfx, unsigned int init_fb);