2 #include <linux/firmware.h>
5 MODULE_FIRMWARE("ast_dp501_fw.bin");
7 static int ast_load_dp501_microcode(struct drm_device *dev)
9 struct ast_private *ast = dev->dev_private;
11 return request_firmware(&ast->dp501_fw, "ast_dp501_fw.bin", dev->dev);
14 static void send_ack(struct ast_private *ast)
17 sendack = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9b, 0xff);
19 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9b, 0x00, sendack);
22 static void send_nack(struct ast_private *ast)
25 sendack = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9b, 0xff);
27 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9b, 0x00, sendack);
30 static bool wait_ack(struct ast_private *ast)
35 waitack = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd2, 0xff);
38 } while ((!waitack) && (retry++ < 1000));
46 static bool wait_nack(struct ast_private *ast)
51 waitack = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd2, 0xff);
54 } while ((waitack) && (retry++ < 1000));
62 static void set_cmd_trigger(struct ast_private *ast)
64 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9b, ~0x40, 0x40);
67 static void clear_cmd_trigger(struct ast_private *ast)
69 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9b, ~0x40, 0x00);
73 static bool wait_fw_ready(struct ast_private *ast)
78 waitready = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd2, 0xff);
81 } while ((!waitready) && (retry++ < 1000));
90 static bool ast_write_cmd(struct drm_device *dev, u8 data)
92 struct ast_private *ast = dev->dev_private;
96 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9a, 0x00, data);
101 clear_cmd_trigger(ast);
105 } while (retry++ < 100);
107 clear_cmd_trigger(ast);
112 static bool ast_write_data(struct drm_device *dev, u8 data)
114 struct ast_private *ast = dev->dev_private;
116 if (wait_nack(ast)) {
118 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9a, 0x00, data);
130 static bool ast_read_data(struct drm_device *dev, u8 *data)
132 struct ast_private *ast = dev->dev_private;
137 if (wait_ack(ast) == false)
139 tmp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd3, 0xff);
141 if (wait_nack(ast) == false) {
149 static void clear_cmd(struct ast_private *ast)
152 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9a, 0x00, 0x00);
156 void ast_set_dp501_video_output(struct drm_device *dev, u8 mode)
158 ast_write_cmd(dev, 0x40);
159 ast_write_data(dev, mode);
164 static u32 get_fw_base(struct ast_private *ast)
166 return ast_mindwm(ast, 0x1e6e2104) & 0x7fffffff;
169 bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)
171 struct ast_private *ast = dev->dev_private;
175 data = ast_mindwm(ast, 0x1e6e2100) & 0x01;
177 boot_address = get_fw_base(ast);
178 for (i = 0; i < size; i += 4)
179 *(u32 *)(addr + i) = ast_mindwm(ast, boot_address + i);
185 static bool ast_launch_m68k(struct drm_device *dev)
187 struct ast_private *ast = dev->dev_private;
188 u32 i, data, len = 0;
193 data = ast_mindwm(ast, 0x1e6e2100) & 0x01;
196 if (ast->dp501_fw_addr) {
197 fw_addr = ast->dp501_fw_addr;
200 if (!ast->dp501_fw &&
201 ast_load_dp501_microcode(dev) < 0)
204 fw_addr = (u8 *)ast->dp501_fw->data;
205 len = ast->dp501_fw->size;
207 /* Get BootAddress */
208 ast_moutdwm(ast, 0x1e6e2000, 0x1688a8a8);
209 data = ast_mindwm(ast, 0x1e6e0004);
210 switch (data & 0x03) {
212 boot_address = 0x44000000;
216 boot_address = 0x48000000;
219 boot_address = 0x50000000;
222 boot_address = 0x60000000;
225 boot_address -= 0x200000; /* -2MB */
227 /* copy image to buffer */
228 for (i = 0; i < len; i += 4) {
229 data = *(u32 *)(fw_addr + i);
230 ast_moutdwm(ast, boot_address + i, data);
234 ast_moutdwm(ast, 0x1e6e2000, 0x1688a8a8);
237 ast_moutdwm(ast, 0x1e6e2104, 0x80000000 + boot_address);
238 ast_moutdwm(ast, 0x1e6e2100, 1);
241 data = ast_mindwm(ast, 0x1e6e2040) & 0xfffff1ff; /* D[11:9] = 100b: UEFI handling */
243 ast_moutdwm(ast, 0x1e6e2040, data);
245 jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x99, 0xfc); /* D[1:0]: Reserved Video Buffer */
247 ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x99, jreg);
252 u8 ast_get_dp501_max_clk(struct drm_device *dev)
254 struct ast_private *ast = dev->dev_private;
255 u32 boot_address, offset, data;
256 u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
258 boot_address = get_fw_base(ast);
260 /* validate FW version */
262 data = ast_mindwm(ast, boot_address + offset);
263 if ((data & 0xf0) != 0x10) /* version: 1x */
266 /* Read Link Capability */
268 *(u32 *)linkcap = ast_mindwm(ast, boot_address + offset);
269 if (linkcap[2] == 0) {
270 linkrate = linkcap[0];
271 linklanes = linkcap[1];
272 data = (linkrate == 0x0a) ? (90 * linklanes) : (54 * linklanes);
280 bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
282 struct ast_private *ast = dev->dev_private;
283 u32 i, boot_address, offset, data;
285 boot_address = get_fw_base(ast);
287 /* validate FW version */
289 data = ast_mindwm(ast, boot_address + offset);
290 if ((data & 0xf0) != 0x10)
293 /* validate PnP Monitor */
295 data = ast_mindwm(ast, boot_address + offset);
301 for (i = 0; i < 128; i += 4) {
302 data = ast_mindwm(ast, boot_address + offset + i);
303 *(u32 *)(ediddata + i) = data;
309 static bool ast_init_dvo(struct drm_device *dev)
311 struct ast_private *ast = dev->dev_private;
314 ast_write32(ast, 0xf004, 0x1e6e0000);
315 ast_write32(ast, 0xf000, 0x1);
316 ast_write32(ast, 0x12000, 0x1688a8a8);
318 jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
319 if (!(jreg & 0x80)) {
320 /* Init SCU DVO Settings */
321 data = ast_read32(ast, 0x12008);
325 ast_write32(ast, 0x12008, data);
327 if (ast->chip == AST2300) {
328 data = ast_read32(ast, 0x12084);
329 /* multi-pins for DVO single-edge */
331 ast_write32(ast, 0x12084, data);
333 data = ast_read32(ast, 0x12088);
334 /* multi-pins for DVO single-edge */
336 ast_write32(ast, 0x12088, data);
338 data = ast_read32(ast, 0x12090);
339 /* multi-pins for DVO single-edge */
342 ast_write32(ast, 0x12090, data);
343 } else { /* AST2400 */
344 data = ast_read32(ast, 0x12088);
345 /* multi-pins for DVO single-edge */
347 ast_write32(ast, 0x12088, data);
349 data = ast_read32(ast, 0x1208c);
350 /* multi-pins for DVO single-edge */
352 ast_write32(ast, 0x1208c, data);
354 data = ast_read32(ast, 0x120a4);
355 /* multi-pins for DVO single-edge */
357 ast_write32(ast, 0x120a4, data);
359 data = ast_read32(ast, 0x120a8);
360 /* multi-pins for DVO single-edge */
362 ast_write32(ast, 0x120a8, data);
364 data = ast_read32(ast, 0x12094);
365 /* multi-pins for DVO single-edge */
367 ast_write32(ast, 0x12094, data);
372 data = ast_read32(ast, 0x1202c);
374 ast_write32(ast, 0x1202c, data);
376 /* Init VGA DVO Settings */
377 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa3, 0xcf, 0x80);
382 static void ast_init_analog(struct drm_device *dev)
384 struct ast_private *ast = dev->dev_private;
388 * Set DAC source to VGA mode in SCU2C via the P2A
389 * bridge. First configure the P2U to target the SCU
390 * in case it isn't at this stage.
392 ast_write32(ast, 0xf004, 0x1e6e0000);
393 ast_write32(ast, 0xf000, 0x1);
395 /* Then unlock the SCU with the magic password */
396 ast_write32(ast, 0x12000, 0x1688a8a8);
397 ast_write32(ast, 0x12000, 0x1688a8a8);
398 ast_write32(ast, 0x12000, 0x1688a8a8);
400 /* Finally, clear bits [17:16] of SCU2c */
401 data = ast_read32(ast, 0x1202c);
403 ast_write32(ast, 0, data);
406 ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa3, 0xcf, 0x00);
409 void ast_init_3rdtx(struct drm_device *dev)
411 struct ast_private *ast = dev->dev_private;
414 if (ast->chip == AST2300 || ast->chip == AST2400) {
415 jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff);
416 switch (jreg & 0x0e) {
421 ast_launch_m68k(dev);
427 if (ast->tx_chip_type == AST_TX_SIL164)
430 ast_init_analog(dev);
435 void ast_release_firmware(struct drm_device *dev)
437 struct ast_private *ast = dev->dev_private;
439 release_firmware(ast->dp501_fw);
440 ast->dp501_fw = NULL;