ati_radeon_fb.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * ATI Radeon Video card Framebuffer driver.
  3. *
  4. * Copyright 2007 Freescale Semiconductor, Inc.
  5. * Zhang Wei <wei.zhang@freescale.com>
  6. * Jason Jin <jason.jin@freescale.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. *
  26. * Some codes of this file is partly ported from Linux kernel
  27. * ATI video framebuffer driver.
  28. *
  29. * Now the driver is tested on below ATI chips:
  30. * 9200
  31. * X300
  32. * X700
  33. *
  34. */
  35. #include <common.h>
  36. #include <command.h>
  37. #include <pci.h>
  38. #include <asm/processor.h>
  39. #include <asm/errno.h>
  40. #include <asm/io.h>
  41. #include <malloc.h>
  42. #include <video_fb.h>
  43. #include "videomodes.h"
  44. #include <radeon.h>
  45. #include "ati_ids.h"
  46. #include "ati_radeon_fb.h"
  47. #undef DEBUG
  48. #ifdef DEBUG
  49. #define DPRINT(x...) printf(x)
  50. #else
  51. #define DPRINT(x...) do{}while(0)
  52. #endif
  53. #ifndef min_t
  54. #define min_t(type,x,y) \
  55. ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
  56. #endif
  57. #define MAX_MAPPED_VRAM (2048*2048*4)
  58. #define MIN_MAPPED_VRAM (1024*768*1)
  59. #define RADEON_BUFFER_ALIGN 0x00000fff
  60. #define SURF_UPPER_BOUND(x,y,bpp) (((((x) * (((y) + 15) & ~15) * (bpp)/8) + RADEON_BUFFER_ALIGN) \
  61. & ~RADEON_BUFFER_ALIGN) - 1)
  62. #define RADEON_CRT_PITCH(width, bpp) ((((width) * (bpp) + ((bpp) * 8 - 1)) / ((bpp) * 8)) | \
  63. ((((width) * (bpp) + ((bpp) * 8 - 1)) / ((bpp) * 8)) << 16))
  64. #define CRTC_H_TOTAL_DISP_VAL(htotal, hdisp) \
  65. (((((htotal) / 8) - 1) & 0x3ff) | (((((hdisp) / 8) - 1) & 0x1ff) << 16))
  66. #define CRTC_HSYNC_STRT_WID_VAL(hsync_srtr, hsync_wid) \
  67. (((hsync_srtr) & 0x1fff) | (((hsync_wid) & 0x3f) << 16))
  68. #define CRTC_V_TOTAL_DISP_VAL(vtotal, vdisp) \
  69. ((((vtotal) - 1) & 0xffff) | (((vdisp) - 1) << 16))
  70. #define CRTC_VSYNC_STRT_WID_VAL(vsync_srtr, vsync_wid) \
  71. ((((vsync_srtr) - 1) & 0xfff) | (((vsync_wid) & 0x1f) << 16))
  72. /*#define PCI_VENDOR_ID_ATI*/
  73. #define PCI_CHIP_RV280_5960 0x5960
  74. #define PCI_CHIP_RV280_5961 0x5961
  75. #define PCI_CHIP_RV280_5962 0x5962
  76. #define PCI_CHIP_RV280_5964 0x5964
  77. #define PCI_CHIP_RV280_5C63 0x5C63
  78. #define PCI_CHIP_RV370_5B60 0x5B60
  79. #define PCI_CHIP_RV380_5657 0x5657
  80. #define PCI_CHIP_R420_554d 0x554d
  81. static struct pci_device_id ati_radeon_pci_ids[] = {
  82. {PCI_VENDOR_ID_ATI, PCI_CHIP_RV280_5960},
  83. {PCI_VENDOR_ID_ATI, PCI_CHIP_RV280_5961},
  84. {PCI_VENDOR_ID_ATI, PCI_CHIP_RV280_5962},
  85. {PCI_VENDOR_ID_ATI, PCI_CHIP_RV280_5964},
  86. {PCI_VENDOR_ID_ATI, PCI_CHIP_RV280_5C63},
  87. {PCI_VENDOR_ID_ATI, PCI_CHIP_RV370_5B60},
  88. {PCI_VENDOR_ID_ATI, PCI_CHIP_RV380_5657},
  89. {PCI_VENDOR_ID_ATI, PCI_CHIP_R420_554d},
  90. {0, 0}
  91. };
  92. static u16 ati_radeon_id_family_table[][2] = {
  93. {PCI_CHIP_RV280_5960, CHIP_FAMILY_RV280},
  94. {PCI_CHIP_RV280_5961, CHIP_FAMILY_RV280},
  95. {PCI_CHIP_RV280_5962, CHIP_FAMILY_RV280},
  96. {PCI_CHIP_RV280_5964, CHIP_FAMILY_RV280},
  97. {PCI_CHIP_RV280_5C63, CHIP_FAMILY_RV280},
  98. {PCI_CHIP_RV370_5B60, CHIP_FAMILY_RV380},
  99. {PCI_CHIP_RV380_5657, CHIP_FAMILY_RV380},
  100. {PCI_CHIP_R420_554d, CHIP_FAMILY_R420},
  101. {0, 0}
  102. };
  103. u16 get_radeon_id_family(u16 device)
  104. {
  105. int i;
  106. for (i=0; ati_radeon_id_family_table[0][i]; i+=2)
  107. if (ati_radeon_id_family_table[0][i] == device)
  108. return ati_radeon_id_family_table[0][i + 1];
  109. return 0;
  110. }
  111. struct radeonfb_info *rinfo;
  112. static void radeon_identify_vram(struct radeonfb_info *rinfo)
  113. {
  114. u32 tmp;
  115. /* framebuffer size */
  116. if ((rinfo->family == CHIP_FAMILY_RS100) ||
  117. (rinfo->family == CHIP_FAMILY_RS200) ||
  118. (rinfo->family == CHIP_FAMILY_RS300)) {
  119. u32 tom = INREG(NB_TOM);
  120. tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024);
  121. radeon_fifo_wait(6);
  122. OUTREG(MC_FB_LOCATION, tom);
  123. OUTREG(DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
  124. OUTREG(CRTC2_DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
  125. OUTREG(OV0_BASE_ADDR, (tom & 0xffff) << 16);
  126. /* This is supposed to fix the crtc2 noise problem. */
  127. OUTREG(GRPH2_BUFFER_CNTL, INREG(GRPH2_BUFFER_CNTL) & ~0x7f0000);
  128. if ((rinfo->family == CHIP_FAMILY_RS100) ||
  129. (rinfo->family == CHIP_FAMILY_RS200)) {
  130. /* This is to workaround the asic bug for RMX, some versions
  131. of BIOS dosen't have this register initialized correctly.
  132. */
  133. OUTREGP(CRTC_MORE_CNTL, CRTC_H_CUTOFF_ACTIVE_EN,
  134. ~CRTC_H_CUTOFF_ACTIVE_EN);
  135. }
  136. } else {
  137. tmp = INREG(CONFIG_MEMSIZE);
  138. }
  139. /* mem size is bits [28:0], mask off the rest */
  140. rinfo->video_ram = tmp & CONFIG_MEMSIZE_MASK;
  141. /*
  142. * Hack to get around some busted production M6's
  143. * reporting no ram
  144. */
  145. if (rinfo->video_ram == 0) {
  146. switch (rinfo->pdev.device) {
  147. case PCI_CHIP_RADEON_LY:
  148. case PCI_CHIP_RADEON_LZ:
  149. rinfo->video_ram = 8192 * 1024;
  150. break;
  151. default:
  152. break;
  153. }
  154. }
  155. /*
  156. * Now try to identify VRAM type
  157. */
  158. if ((rinfo->family >= CHIP_FAMILY_R300) ||
  159. (INREG(MEM_SDRAM_MODE_REG) & (1<<30)))
  160. rinfo->vram_ddr = 1;
  161. else
  162. rinfo->vram_ddr = 0;
  163. tmp = INREG(MEM_CNTL);
  164. if (IS_R300_VARIANT(rinfo)) {
  165. tmp &= R300_MEM_NUM_CHANNELS_MASK;
  166. switch (tmp) {
  167. case 0: rinfo->vram_width = 64; break;
  168. case 1: rinfo->vram_width = 128; break;
  169. case 2: rinfo->vram_width = 256; break;
  170. default: rinfo->vram_width = 128; break;
  171. }
  172. } else if ((rinfo->family == CHIP_FAMILY_RV100) ||
  173. (rinfo->family == CHIP_FAMILY_RS100) ||
  174. (rinfo->family == CHIP_FAMILY_RS200)){
  175. if (tmp & RV100_MEM_HALF_MODE)
  176. rinfo->vram_width = 32;
  177. else
  178. rinfo->vram_width = 64;
  179. } else {
  180. if (tmp & MEM_NUM_CHANNELS_MASK)
  181. rinfo->vram_width = 128;
  182. else
  183. rinfo->vram_width = 64;
  184. }
  185. /* This may not be correct, as some cards can have half of channel disabled
  186. * ToDo: identify these cases
  187. */
  188. DPRINT("radeonfb: Found %ldk of %s %d bits wide videoram\n",
  189. rinfo->video_ram / 1024,
  190. rinfo->vram_ddr ? "DDR" : "SDRAM",
  191. rinfo->vram_width);
  192. }
  193. static void radeon_write_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs *mode)
  194. {
  195. int i;
  196. radeon_fifo_wait(20);
  197. #if 0
  198. /* Workaround from XFree */
  199. if (rinfo->is_mobility) {
  200. /* A temporal workaround for the occational blanking on certain laptop
  201. * panels. This appears to related to the PLL divider registers
  202. * (fail to lock?). It occurs even when all dividers are the same
  203. * with their old settings. In this case we really don't need to
  204. * fiddle with PLL registers. By doing this we can avoid the blanking
  205. * problem with some panels.
  206. */
  207. if ((mode->ppll_ref_div == (INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK)) &&
  208. (mode->ppll_div_3 == (INPLL(PPLL_DIV_3) &
  209. (PPLL_POST3_DIV_MASK | PPLL_FB3_DIV_MASK)))) {
  210. /* We still have to force a switch to selected PPLL div thanks to
  211. * an XFree86 driver bug which will switch it away in some cases
  212. * even when using UseFDev */
  213. OUTREGP(CLOCK_CNTL_INDEX,
  214. mode->clk_cntl_index & PPLL_DIV_SEL_MASK,
  215. ~PPLL_DIV_SEL_MASK);
  216. radeon_pll_errata_after_index(rinfo);
  217. radeon_pll_errata_after_data(rinfo);
  218. return;
  219. }
  220. }
  221. #endif
  222. if(rinfo->pdev.device == PCI_CHIP_RV370_5B60) return;
  223. /* Swich VCKL clock input to CPUCLK so it stays fed while PPLL updates*/
  224. OUTPLLP(VCLK_ECP_CNTL, VCLK_SRC_SEL_CPUCLK, ~VCLK_SRC_SEL_MASK);
  225. /* Reset PPLL & enable atomic update */
  226. OUTPLLP(PPLL_CNTL,
  227. PPLL_RESET | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN,
  228. ~(PPLL_RESET | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN));
  229. /* Switch to selected PPLL divider */
  230. OUTREGP(CLOCK_CNTL_INDEX,
  231. mode->clk_cntl_index & PPLL_DIV_SEL_MASK,
  232. ~PPLL_DIV_SEL_MASK);
  233. /* Set PPLL ref. div */
  234. if (rinfo->family == CHIP_FAMILY_R300 ||
  235. rinfo->family == CHIP_FAMILY_RS300 ||
  236. rinfo->family == CHIP_FAMILY_R350 ||
  237. rinfo->family == CHIP_FAMILY_RV350) {
  238. if (mode->ppll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) {
  239. /* When restoring console mode, use saved PPLL_REF_DIV
  240. * setting.
  241. */
  242. OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, 0);
  243. } else {
  244. /* R300 uses ref_div_acc field as real ref divider */
  245. OUTPLLP(PPLL_REF_DIV,
  246. (mode->ppll_ref_div << R300_PPLL_REF_DIV_ACC_SHIFT),
  247. ~R300_PPLL_REF_DIV_ACC_MASK);
  248. }
  249. } else
  250. OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK);
  251. /* Set PPLL divider 3 & post divider*/
  252. OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK);
  253. OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK);
  254. /* Write update */
  255. while (INPLL(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R)
  256. ;
  257. OUTPLLP(PPLL_REF_DIV, PPLL_ATOMIC_UPDATE_W, ~PPLL_ATOMIC_UPDATE_W);
  258. /* Wait read update complete */
  259. /* FIXME: Certain revisions of R300 can't recover here. Not sure of
  260. the cause yet, but this workaround will mask the problem for now.
  261. Other chips usually will pass at the very first test, so the
  262. workaround shouldn't have any effect on them. */
  263. for (i = 0; (i < 10000 && INPLL(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R); i++)
  264. ;
  265. OUTPLL(HTOTAL_CNTL, 0);
  266. /* Clear reset & atomic update */
  267. OUTPLLP(PPLL_CNTL, 0,
  268. ~(PPLL_RESET | PPLL_SLEEP | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN));
  269. /* We may want some locking ... oh well */
  270. udelay(5000);
  271. /* Switch back VCLK source to PPLL */
  272. OUTPLLP(VCLK_ECP_CNTL, VCLK_SRC_SEL_PPLLCLK, ~VCLK_SRC_SEL_MASK);
  273. }
  274. typedef struct {
  275. u16 reg;
  276. u32 val;
  277. } reg_val;
  278. #if 0 /* unused ? -> scheduled for removal */
  279. /* these common regs are cleared before mode setting so they do not
  280. * interfere with anything
  281. */
  282. static reg_val common_regs[] = {
  283. { OVR_CLR, 0 },
  284. { OVR_WID_LEFT_RIGHT, 0 },
  285. { OVR_WID_TOP_BOTTOM, 0 },
  286. { OV0_SCALE_CNTL, 0 },
  287. { SUBPIC_CNTL, 0 },
  288. { VIPH_CONTROL, 0 },
  289. { I2C_CNTL_1, 0 },
  290. { GEN_INT_CNTL, 0 },
  291. { CAP0_TRIG_CNTL, 0 },
  292. { CAP1_TRIG_CNTL, 0 },
  293. };
  294. #endif /* 0 */
  295. void radeon_setmode(void)
  296. {
  297. struct radeon_regs *mode = malloc(sizeof(struct radeon_regs));
  298. mode->crtc_gen_cntl = 0x03000200;
  299. mode->crtc_ext_cntl = 0x00008048;
  300. mode->dac_cntl = 0xff002100;
  301. mode->crtc_h_total_disp = 0x4f0063;
  302. mode->crtc_h_sync_strt_wid = 0x8c02a2;
  303. mode->crtc_v_total_disp = 0x01df020c;
  304. mode->crtc_v_sync_strt_wid = 0x8201ea;
  305. mode->crtc_pitch = 0x00500050;
  306. OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
  307. OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
  308. ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS));
  309. OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
  310. OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
  311. OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
  312. OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
  313. OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
  314. OUTREG(CRTC_OFFSET, 0);
  315. OUTREG(CRTC_OFFSET_CNTL, 0);
  316. OUTREG(CRTC_PITCH, mode->crtc_pitch);
  317. mode->clk_cntl_index = 0x300;
  318. mode->ppll_ref_div = 0xc;
  319. mode->ppll_div_3 = 0x00030059;
  320. radeon_write_pll_regs(rinfo, mode);
  321. }
  322. static void set_pal(void)
  323. {
  324. int idx, val = 0;
  325. for (idx = 0; idx < 256; idx++) {
  326. OUTREG8(PALETTE_INDEX, idx);
  327. OUTREG(PALETTE_DATA, val);
  328. val += 0x00010101;
  329. }
  330. }
  331. void radeon_setmode_9200(int vesa_idx, int bpp)
  332. {
  333. struct radeon_regs *mode = malloc(sizeof(struct radeon_regs));
  334. mode->crtc_gen_cntl = CRTC_EN | CRTC_EXT_DISP_EN;
  335. mode->crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN | CRTC_CRT_ON;
  336. mode->dac_cntl = DAC_MASK_ALL | DAC_VGA_ADR_EN | DAC_8BIT_EN;
  337. mode->crtc_offset_cntl = CRTC_OFFSET_CNTL__CRTC_TILE_EN;
  338. switch (bpp) {
  339. case 24:
  340. mode->crtc_gen_cntl |= 0x6 << 8; /* x888 */
  341. #if defined(__BIG_ENDIAN)
  342. mode->surface_cntl = NONSURF_AP0_SWP_32BPP | NONSURF_AP1_SWP_32BPP;
  343. mode->surf_info[0] = NONSURF_AP0_SWP_32BPP | NONSURF_AP1_SWP_32BPP;
  344. #endif
  345. break;
  346. case 16:
  347. mode->crtc_gen_cntl |= 0x4 << 8; /* 565 */
  348. #if defined(__BIG_ENDIAN)
  349. mode->surface_cntl = NONSURF_AP0_SWP_16BPP | NONSURF_AP1_SWP_16BPP;
  350. mode->surf_info[0] = NONSURF_AP0_SWP_16BPP | NONSURF_AP1_SWP_16BPP;
  351. #endif
  352. break;
  353. default:
  354. mode->crtc_gen_cntl |= 0x2 << 8; /* palette */
  355. mode->surface_cntl = 0x00000000;
  356. break;
  357. }
  358. switch (vesa_idx) {
  359. case RES_MODE_1280x1024:
  360. mode->crtc_h_total_disp = CRTC_H_TOTAL_DISP_VAL(1688,1280);
  361. mode->crtc_v_total_disp = CRTC_V_TOTAL_DISP_VAL(1066,1024);
  362. mode->crtc_v_sync_strt_wid = CRTC_VSYNC_STRT_WID_VAL(1025,3);
  363. #if defined(CONFIG_RADEON_VREFRESH_75HZ)
  364. mode->crtc_h_sync_strt_wid = CRTC_HSYNC_STRT_WID_VAL(1288,18);
  365. mode->ppll_div_3 = 0x00010078;
  366. #else /* default @ 60 Hz */
  367. mode->crtc_h_sync_strt_wid = CRTC_HSYNC_STRT_WID_VAL(1320,14);
  368. mode->ppll_div_3 = 0x00010060;
  369. #endif
  370. /*
  371. * for this mode pitch expands to the same value for 32, 16 and 8 bpp,
  372. * so we set it here once only.
  373. */
  374. mode->crtc_pitch = RADEON_CRT_PITCH(1280,32);
  375. switch (bpp) {
  376. case 24:
  377. mode->surf_info[0] |= R200_SURF_TILE_COLOR_MACRO | (1280 * 4 / 16);
  378. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(1280,1024,32);
  379. break;
  380. case 16:
  381. mode->surf_info[0] |= R200_SURF_TILE_COLOR_MACRO | (1280 * 2 / 16);
  382. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(1280,1024,16);
  383. break;
  384. default: /* 8 bpp */
  385. mode->surf_info[0] = R200_SURF_TILE_COLOR_MACRO | (1280 * 1 / 16);
  386. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(1280,1024,8);
  387. break;
  388. }
  389. break;
  390. case RES_MODE_1024x768:
  391. #if defined(CONFIG_RADEON_VREFRESH_75HZ)
  392. mode->crtc_h_total_disp = CRTC_H_TOTAL_DISP_VAL(1312,1024);
  393. mode->crtc_h_sync_strt_wid = CRTC_HSYNC_STRT_WID_VAL(1032,12);
  394. mode->crtc_v_total_disp = CRTC_V_TOTAL_DISP_VAL(800,768);
  395. mode->crtc_v_sync_strt_wid = CRTC_VSYNC_STRT_WID_VAL(769,3);
  396. mode->ppll_div_3 = 0x0002008c;
  397. #else /* @ 60 Hz */
  398. mode->crtc_h_total_disp = CRTC_H_TOTAL_DISP_VAL(1344,1024);
  399. mode->crtc_h_sync_strt_wid = CRTC_HSYNC_STRT_WID_VAL(1040,17) | CRTC_H_SYNC_POL;
  400. mode->crtc_v_total_disp = CRTC_V_TOTAL_DISP_VAL(806,768);
  401. mode->crtc_v_sync_strt_wid = CRTC_VSYNC_STRT_WID_VAL(771,6) | CRTC_V_SYNC_POL;
  402. mode->ppll_div_3 = 0x00020074;
  403. #endif
  404. /* also same pitch value for 32, 16 and 8 bpp */
  405. mode->crtc_pitch = RADEON_CRT_PITCH(1024,32);
  406. switch (bpp) {
  407. case 24:
  408. mode->surf_info[0] |= R200_SURF_TILE_COLOR_MACRO | (1024 * 4 / 16);
  409. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(1024,768,32);
  410. break;
  411. case 16:
  412. mode->surf_info[0] |= R200_SURF_TILE_COLOR_MACRO | (1024 * 2 / 16);
  413. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(1024,768,16);
  414. break;
  415. default: /* 8 bpp */
  416. mode->surf_info[0] = R200_SURF_TILE_COLOR_MACRO | (1024 * 1 / 16);
  417. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(1024,768,8);
  418. break;
  419. }
  420. break;
  421. case RES_MODE_800x600:
  422. mode->crtc_h_total_disp = CRTC_H_TOTAL_DISP_VAL(1056,800);
  423. #if defined(CONFIG_RADEON_VREFRESH_75HZ)
  424. mode->crtc_h_sync_strt_wid = CRTC_HSYNC_STRT_WID_VAL(808,10);
  425. mode->crtc_v_total_disp = CRTC_V_TOTAL_DISP_VAL(625,600);
  426. mode->crtc_v_sync_strt_wid = CRTC_VSYNC_STRT_WID_VAL(601,3);
  427. mode->ppll_div_3 = 0x000300b0;
  428. #else /* @ 60 Hz */
  429. mode->crtc_h_sync_strt_wid = CRTC_HSYNC_STRT_WID_VAL(832,16);
  430. mode->crtc_v_total_disp = CRTC_V_TOTAL_DISP_VAL(628,600);
  431. mode->crtc_v_sync_strt_wid = CRTC_VSYNC_STRT_WID_VAL(601,4);
  432. mode->ppll_div_3 = 0x0003008e;
  433. #endif
  434. switch (bpp) {
  435. case 24:
  436. mode->crtc_pitch = RADEON_CRT_PITCH(832,32);
  437. mode->surf_info[0] |= R200_SURF_TILE_COLOR_MACRO | (832 * 4 / 16);
  438. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(832,600,32);
  439. break;
  440. case 16:
  441. mode->crtc_pitch = RADEON_CRT_PITCH(896,16);
  442. mode->surf_info[0] |= R200_SURF_TILE_COLOR_MACRO | (896 * 2 / 16);
  443. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(896,600,16);
  444. break;
  445. default: /* 8 bpp */
  446. mode->crtc_pitch = RADEON_CRT_PITCH(1024,8);
  447. mode->surf_info[0] = R200_SURF_TILE_COLOR_MACRO | (1024 * 1 / 16);
  448. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(1024,600,8);
  449. break;
  450. }
  451. break;
  452. default: /* RES_MODE_640x480 */
  453. #if defined(CONFIG_RADEON_VREFRESH_75HZ)
  454. mode->crtc_h_total_disp = CRTC_H_TOTAL_DISP_VAL(840,640);
  455. mode->crtc_h_sync_strt_wid = CRTC_HSYNC_STRT_WID_VAL(648,8) | CRTC_H_SYNC_POL;
  456. mode->crtc_v_total_disp = CRTC_V_TOTAL_DISP_VAL(500,480);
  457. mode->crtc_v_sync_strt_wid = CRTC_VSYNC_STRT_WID_VAL(481,3) | CRTC_V_SYNC_POL;
  458. mode->ppll_div_3 = 0x00030070;
  459. #else /* @ 60 Hz */
  460. mode->crtc_h_total_disp = CRTC_H_TOTAL_DISP_VAL(800,640);
  461. mode->crtc_h_sync_strt_wid = CRTC_HSYNC_STRT_WID_VAL(674,12) | CRTC_H_SYNC_POL;
  462. mode->crtc_v_total_disp = CRTC_V_TOTAL_DISP_VAL(525,480);
  463. mode->crtc_v_sync_strt_wid = CRTC_VSYNC_STRT_WID_VAL(491,2) | CRTC_V_SYNC_POL;
  464. mode->ppll_div_3 = 0x00030059;
  465. #endif
  466. /* also same pitch value for 32, 16 and 8 bpp */
  467. mode->crtc_pitch = RADEON_CRT_PITCH(640,32);
  468. switch (bpp) {
  469. case 24:
  470. mode->surf_info[0] |= R200_SURF_TILE_COLOR_MACRO | (640 * 4 / 16);
  471. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(640,480,32);
  472. break;
  473. case 16:
  474. mode->surf_info[0] |= R200_SURF_TILE_COLOR_MACRO | (640 * 2 / 16);
  475. mode->surf_upper_bound[0] = SURF_UPPER_BOUND(640,480,16);
  476. break;
  477. default: /* 8 bpp */
  478. mode->crtc_offset_cntl = 0x00000000;
  479. break;
  480. }
  481. break;
  482. }
  483. OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl | CRTC_DISP_REQ_EN_B);
  484. OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
  485. (CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS));
  486. OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
  487. OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
  488. OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
  489. OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
  490. OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
  491. OUTREG(CRTC_OFFSET, 0);
  492. OUTREG(CRTC_OFFSET_CNTL, mode->crtc_offset_cntl);
  493. OUTREG(CRTC_PITCH, mode->crtc_pitch);
  494. OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
  495. mode->clk_cntl_index = 0x300;
  496. mode->ppll_ref_div = 0xc;
  497. radeon_write_pll_regs(rinfo, mode);
  498. OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
  499. ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS));
  500. OUTREG(SURFACE0_INFO, mode->surf_info[0]);
  501. OUTREG(SURFACE0_LOWER_BOUND, 0);
  502. OUTREG(SURFACE0_UPPER_BOUND, mode->surf_upper_bound[0]);
  503. OUTREG(SURFACE_CNTL, mode->surface_cntl);
  504. if (bpp > 8)
  505. set_pal();
  506. free(mode);
  507. }
  508. #include "../bios_emulator/include/biosemu.h"
  509. extern int BootVideoCardBIOS(pci_dev_t pcidev, BE_VGAInfo ** pVGAInfo, int cleanUp);
  510. int radeon_probe(struct radeonfb_info *rinfo)
  511. {
  512. pci_dev_t pdev;
  513. u16 did;
  514. pdev = pci_find_devices(ati_radeon_pci_ids, 0);
  515. if (pdev != -1) {
  516. pci_read_config_word(pdev, PCI_DEVICE_ID, &did);
  517. printf("ATI Radeon video card (%04x, %04x) found @(%d:%d:%d)\n",
  518. PCI_VENDOR_ID_ATI, did, (pdev >> 16) & 0xff,
  519. (pdev >> 11) & 0x1f, (pdev >> 8) & 0x7);
  520. strcpy(rinfo->name, "ATI Radeon");
  521. rinfo->pdev.vendor = PCI_VENDOR_ID_ATI;
  522. rinfo->pdev.device = did;
  523. rinfo->family = get_radeon_id_family(rinfo->pdev.device);
  524. pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0,
  525. &rinfo->fb_base_phys);
  526. pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2,
  527. &rinfo->mmio_base_phys);
  528. rinfo->fb_base_phys &= 0xfffff000;
  529. rinfo->mmio_base_phys &= ~0x04;
  530. rinfo->mmio_base = (void *)rinfo->mmio_base_phys;
  531. DPRINT("rinfo->mmio_base = 0x%x\n",rinfo->mmio_base);
  532. rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16;
  533. DPRINT("rinfo->fb_local_base = 0x%x\n",rinfo->fb_local_base);
  534. /* PostBIOS with x86 emulater */
  535. BootVideoCardBIOS(pdev, NULL, 0);
  536. /*
  537. * Check for errata
  538. * (These will be added in the future for the chipfamily
  539. * R300, RV200, RS200, RV100, RS100.)
  540. */
  541. /* Get VRAM size and type */
  542. radeon_identify_vram(rinfo);
  543. rinfo->mapped_vram = min_t(unsigned long, MAX_MAPPED_VRAM,
  544. rinfo->video_ram);
  545. rinfo->fb_base = (void *)rinfo->fb_base_phys;
  546. DPRINT("Radeon: framebuffer base phy address 0x%08x," \
  547. "MMIO base phy address 0x%08x," \
  548. "framebuffer local base 0x%08x.\n ",
  549. rinfo->fb_base_phys, rinfo->mmio_base_phys,
  550. rinfo->fb_local_base);
  551. return 0;
  552. }
  553. return -1;
  554. }
  555. /*
  556. * The Graphic Device
  557. */
  558. GraphicDevice ctfb;
  559. #define CURSOR_SIZE 0x1000 /* in KByte for HW Cursor */
  560. #define PATTERN_ADR (pGD->dprBase + CURSOR_SIZE) /* pattern Memory after Cursor Memory */
  561. #define PATTERN_SIZE 8*8*4 /* 4 Bytes per Pixel 8 x 8 Pixel */
  562. #define ACCELMEMORY (CURSOR_SIZE + PATTERN_SIZE) /* reserved Memory for BITBlt and hw cursor */
  563. void *video_hw_init(void)
  564. {
  565. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  566. u32 *vm;
  567. char *penv;
  568. unsigned long t1, hsynch, vsynch;
  569. int bits_per_pixel, i, tmp, vesa_idx = 0, videomode;
  570. struct ctfb_res_modes *res_mode;
  571. struct ctfb_res_modes var_mode;
  572. rinfo = malloc(sizeof(struct radeonfb_info));
  573. printf("Video: ");
  574. if(radeon_probe(rinfo)) {
  575. printf("No radeon video card found!\n");
  576. return NULL;
  577. }
  578. tmp = 0;
  579. videomode = CONFIG_SYS_DEFAULT_VIDEO_MODE;
  580. /* get video mode via environment */
  581. if ((penv = getenv ("videomode")) != NULL) {
  582. /* deceide if it is a string */
  583. if (penv[0] <= '9') {
  584. videomode = (int) simple_strtoul (penv, NULL, 16);
  585. tmp = 1;
  586. }
  587. } else {
  588. tmp = 1;
  589. }
  590. if (tmp) {
  591. /* parameter are vesa modes */
  592. /* search params */
  593. for (i = 0; i < VESA_MODES_COUNT; i++) {
  594. if (vesa_modes[i].vesanr == videomode)
  595. break;
  596. }
  597. if (i == VESA_MODES_COUNT) {
  598. printf ("no VESA Mode found, switching to mode 0x%x ", CONFIG_SYS_DEFAULT_VIDEO_MODE);
  599. i = 0;
  600. }
  601. res_mode = (struct ctfb_res_modes *) &res_mode_init[vesa_modes[i].resindex];
  602. bits_per_pixel = vesa_modes[i].bits_per_pixel;
  603. vesa_idx = vesa_modes[i].resindex;
  604. } else {
  605. res_mode = (struct ctfb_res_modes *) &var_mode;
  606. bits_per_pixel = video_get_params (res_mode, penv);
  607. }
  608. /* calculate hsynch and vsynch freq (info only) */
  609. t1 = (res_mode->left_margin + res_mode->xres +
  610. res_mode->right_margin + res_mode->hsync_len) / 8;
  611. t1 *= 8;
  612. t1 *= res_mode->pixclock;
  613. t1 /= 1000;
  614. hsynch = 1000000000L / t1;
  615. t1 *= (res_mode->upper_margin + res_mode->yres +
  616. res_mode->lower_margin + res_mode->vsync_len);
  617. t1 /= 1000;
  618. vsynch = 1000000000L / t1;
  619. /* fill in Graphic device struct */
  620. sprintf (pGD->modeIdent, "%dx%dx%d %ldkHz %ldHz", res_mode->xres,
  621. res_mode->yres, bits_per_pixel, (hsynch / 1000),
  622. (vsynch / 1000));
  623. printf ("%s\n", pGD->modeIdent);
  624. pGD->winSizeX = res_mode->xres;
  625. pGD->winSizeY = res_mode->yres;
  626. pGD->plnSizeX = res_mode->xres;
  627. pGD->plnSizeY = res_mode->yres;
  628. switch (bits_per_pixel) {
  629. case 24:
  630. pGD->gdfBytesPP = 4;
  631. pGD->gdfIndex = GDF_32BIT_X888RGB;
  632. if (res_mode->xres == 800) {
  633. pGD->winSizeX = 832;
  634. pGD->plnSizeX = 832;
  635. }
  636. break;
  637. case 16:
  638. pGD->gdfBytesPP = 2;
  639. pGD->gdfIndex = GDF_16BIT_565RGB;
  640. if (res_mode->xres == 800) {
  641. pGD->winSizeX = 896;
  642. pGD->plnSizeX = 896;
  643. }
  644. break;
  645. default:
  646. if (res_mode->xres == 800) {
  647. pGD->winSizeX = 1024;
  648. pGD->plnSizeX = 1024;
  649. }
  650. pGD->gdfBytesPP = 1;
  651. pGD->gdfIndex = GDF__8BIT_INDEX;
  652. break;
  653. }
  654. pGD->isaBase = CONFIG_SYS_ISA_IO_BASE_ADDRESS;
  655. pGD->pciBase = rinfo->fb_base_phys;
  656. pGD->frameAdrs = rinfo->fb_base_phys;
  657. pGD->memSize = 64 * 1024 * 1024;
  658. /* Cursor Start Address */
  659. pGD->dprBase =
  660. (pGD->winSizeX * pGD->winSizeY * pGD->gdfBytesPP) + rinfo->fb_base_phys;
  661. if ((pGD->dprBase & 0x0fff) != 0) {
  662. /* allign it */
  663. pGD->dprBase &= 0xfffff000;
  664. pGD->dprBase += 0x00001000;
  665. }
  666. DPRINT ("Cursor Start %x Pattern Start %x\n", pGD->dprBase,
  667. PATTERN_ADR);
  668. pGD->vprBase = rinfo->fb_base_phys; /* Dummy */
  669. pGD->cprBase = rinfo->fb_base_phys; /* Dummy */
  670. /* set up Hardware */
  671. /* Clear video memory (only visible screen area) */
  672. i = pGD->winSizeX * pGD->winSizeY * pGD->gdfBytesPP / 4;
  673. vm = (unsigned int *) pGD->pciBase;
  674. while (i--)
  675. *vm++ = 0;
  676. /*SetDrawingEngine (bits_per_pixel);*/
  677. if (rinfo->family == CHIP_FAMILY_RV280)
  678. radeon_setmode_9200(vesa_idx, bits_per_pixel);
  679. else
  680. radeon_setmode();
  681. return ((void *) pGD);
  682. }
  683. void video_set_lut (unsigned int index, /* color number */
  684. unsigned char r, /* red */
  685. unsigned char g, /* green */
  686. unsigned char b /* blue */
  687. )
  688. {
  689. OUTREG(PALETTE_INDEX, index);
  690. OUTREG(PALETTE_DATA, (r << 16) | (g << 8) | b);
  691. }