1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * File taken from the Linux ast driver (v3.18.5)
5 * coreboot-specific includes added at top and/or contents modified
6 * as needed to function within the coreboot environment.
13 static void send_ack(struct ast_private
*ast
)
16 sendack
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x9b, 0xff);
18 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x9b, 0x00, sendack
);
21 static void send_nack(struct ast_private
*ast
)
24 sendack
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x9b, 0xff);
26 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x9b, 0x00, sendack
);
29 static bool wait_ack(struct ast_private
*ast
)
34 waitack
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd2, 0xff);
37 } while ((!waitack
) && (retry
++ < 1000));
45 static bool wait_nack(struct ast_private
*ast
)
50 waitack
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd2, 0xff);
53 } while ((waitack
) && (retry
++ < 1000));
61 static void set_cmd_trigger(struct ast_private
*ast
)
63 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x9b, ~0x40, 0x40);
66 static void clear_cmd_trigger(struct ast_private
*ast
)
68 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x9b, ~0x40, 0x00);
71 static bool ast_write_cmd(struct drm_device
*dev
, u8 data
)
73 struct ast_private
*ast
= dev
->dev_private
;
77 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x9a, 0x00, data
);
82 clear_cmd_trigger(ast
);
86 } while (retry
++ < 100);
88 clear_cmd_trigger(ast
);
93 static bool ast_write_data(struct drm_device
*dev
, u8 data
)
95 struct ast_private
*ast
= dev
->dev_private
;
99 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x9a, 0x00, data
);
110 void ast_set_dp501_video_output(struct drm_device
*dev
, u8 mode
)
112 ast_write_cmd(dev
, 0x40);
113 ast_write_data(dev
, mode
);
118 static u32
get_fw_base(struct ast_private
*ast
)
120 return ast_mindwm(ast
, 0x1e6e2104) & 0x7fffffff;
123 bool ast_backup_fw(struct drm_device
*dev
, u8
*addr
, u32 size
)
125 struct ast_private
*ast
= dev
->dev_private
;
129 data
= ast_mindwm(ast
, 0x1e6e2100) & 0x01;
131 boot_address
= get_fw_base(ast
);
132 for (i
= 0; i
< size
; i
+= 4)
133 *(u32
*)(addr
+ i
) = ast_mindwm(ast
, boot_address
+ i
);
139 static bool ast_launch_m68k(struct drm_device
*dev
)
141 struct ast_private
*ast
= dev
->dev_private
;
142 u32 i
, data
, len
= 0;
147 data
= ast_mindwm(ast
, 0x1e6e2100) & 0x01;
149 if (ast
->dp501_fw_addr
) {
150 fw_addr
= ast
->dp501_fw_addr
;
156 fw_addr
= (u8
*)ast
->dp501_fw
->data
;
157 len
= ast
->dp501_fw
->size
;
159 /* Get BootAddress */
160 ast_moutdwm(ast
, 0x1e6e2000, 0x1688a8a8);
161 data
= ast_mindwm(ast
, 0x1e6e0004);
162 switch (data
& 0x03) {
164 boot_address
= 0x44000000;
168 boot_address
= 0x48000000;
171 boot_address
= 0x50000000;
174 boot_address
= 0x60000000;
177 boot_address
-= 0x200000; /* -2MB */
179 /* copy image to buffer */
180 for (i
= 0; i
< len
; i
+= 4) {
181 data
= *(u32
*)(fw_addr
+ i
);
182 ast_moutdwm(ast
, boot_address
+ i
, data
);
186 ast_moutdwm(ast
, 0x1e6e2000, 0x1688a8a8);
189 ast_moutdwm(ast
, 0x1e6e2104, 0x80000000 + boot_address
);
190 ast_moutdwm(ast
, 0x1e6e2100, 1);
193 data
= ast_mindwm(ast
, 0x1e6e2040) & 0xfffff1ff; /* D[11:9] = 100b: UEFI handling */
195 ast_moutdwm(ast
, 0x1e6e2040, data
);
197 jreg
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0x99, 0xfc); /* D[1:0]: Reserved Video Buffer */
199 ast_set_index_reg(ast
, AST_IO_CRTC_PORT
, 0x99, jreg
);
204 u8
ast_get_dp501_max_clk(struct drm_device
*dev
)
206 struct ast_private
*ast
= dev
->dev_private
;
207 u32 boot_address
, offset
, data
;
208 u8 linkcap
[4], linkrate
, linklanes
, maxclk
= 0xff;
210 boot_address
= get_fw_base(ast
);
212 /* validate FW version */
214 data
= ast_mindwm(ast
, boot_address
+ offset
);
215 if ((data
& 0xf0) != 0x10) /* version: 1x */
218 /* Read Link Capability */
220 *(u32
*)linkcap
= ast_mindwm(ast
, boot_address
+ offset
);
221 if (linkcap
[2] == 0) {
222 linkrate
= linkcap
[0];
223 linklanes
= linkcap
[1];
224 data
= (linkrate
== 0x0a) ? (90 * linklanes
) : (54 * linklanes
);
232 bool ast_dp501_read_edid(struct drm_device
*dev
, u8
*ediddata
)
234 struct ast_private
*ast
= dev
->dev_private
;
235 u32 i
, boot_address
, offset
, data
;
237 boot_address
= get_fw_base(ast
);
239 /* validate FW version */
241 data
= ast_mindwm(ast
, boot_address
+ offset
);
242 if ((data
& 0xf0) != 0x10)
245 /* validate PnP Monitor */
247 data
= ast_mindwm(ast
, boot_address
+ offset
);
253 for (i
= 0; i
< 128; i
+= 4) {
254 data
= ast_mindwm(ast
, boot_address
+ offset
+ i
);
255 *(u32
*)(ediddata
+ i
) = data
;
261 static bool ast_init_dvo(struct drm_device
*dev
)
263 struct ast_private
*ast
= dev
->dev_private
;
266 ast_write32(ast
, 0xf004, 0x1e6e0000);
267 ast_write32(ast
, 0xf000, 0x1);
268 ast_write32(ast
, 0x12000, 0x1688a8a8);
270 jreg
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd0, 0xff);
271 if (!(jreg
& 0x80)) {
272 /* Init SCU DVO Settings */
273 data
= ast_read32(ast
, 0x12008);
277 ast_write32(ast
, 0x12008, data
);
279 if (ast
->chip
== AST2300
) {
280 data
= ast_read32(ast
, 0x12084);
281 /* multi-pins for DVO single-edge */
283 ast_write32(ast
, 0x12084, data
);
285 data
= ast_read32(ast
, 0x12088);
286 /* multi-pins for DVO single-edge */
288 ast_write32(ast
, 0x12088, data
);
290 data
= ast_read32(ast
, 0x12090);
291 /* multi-pins for DVO single-edge */
294 ast_write32(ast
, 0x12090, data
);
295 } else { /* AST2400 */
296 data
= ast_read32(ast
, 0x12088);
297 /* multi-pins for DVO single-edge */
299 ast_write32(ast
, 0x12088, data
);
301 data
= ast_read32(ast
, 0x1208c);
302 /* multi-pins for DVO single-edge */
304 ast_write32(ast
, 0x1208c, data
);
306 data
= ast_read32(ast
, 0x120a4);
307 /* multi-pins for DVO single-edge */
309 ast_write32(ast
, 0x120a4, data
);
311 data
= ast_read32(ast
, 0x120a8);
312 /* multi-pins for DVO single-edge */
314 ast_write32(ast
, 0x120a8, data
);
316 data
= ast_read32(ast
, 0x12094);
317 /* multi-pins for DVO single-edge */
319 ast_write32(ast
, 0x12094, data
);
324 data
= ast_read32(ast
, 0x1202c);
326 ast_write32(ast
, 0x1202c, data
);
328 /* Init VGA DVO Settings */
329 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xa3, 0xcf, 0x80);
333 static void ast_init_analog(struct drm_device
*dev
)
335 struct ast_private
*ast
= dev
->dev_private
;
339 * Set DAC source to VGA mode in SCU2C via the P2A
340 * bridge. First configure the P2U to target the SCU
341 * in case it isn't at this stage.
343 ast_write32(ast
, 0xf004, 0x1e6e0000);
344 ast_write32(ast
, 0xf000, 0x1);
346 /* Then unlock the SCU with the magic password */
347 ast_write32(ast
, 0x12000, 0x1688a8a8);
348 ast_write32(ast
, 0x12000, 0x1688a8a8);
349 ast_write32(ast
, 0x12000, 0x1688a8a8);
351 /* Finally, clear bits [17:16] of SCU2c */
352 data
= ast_read32(ast
, 0x1202c);
354 ast_write32(ast
, 0, data
);
357 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xa3, 0xcf, 0x00);
360 void ast_init_3rdtx(struct drm_device
*dev
)
362 struct ast_private
*ast
= dev
->dev_private
;
365 if (ast
->chip
== AST2300
|| ast
->chip
== AST2400
) {
366 jreg
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xd1, 0xff);
367 switch (jreg
& 0x0e) {
372 ast_launch_m68k(dev
);
378 if (ast
->tx_chip_type
== AST_TX_SIL164
)
381 ast_init_analog(dev
);