mb862xx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. * (C) Copyright 2007
  3. * DENX Software Engineering, Anatolij Gustschin, agust@denx.de
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * mb862xx.c - Graphic interface for Fujitsu CoralP/Lime
  25. * PCI and video mode code was derived from smiLynxEM driver.
  26. */
  27. #include <common.h>
  28. #include <asm/io.h>
  29. #include <pci.h>
  30. #include <video_fb.h>
  31. #include "videomodes.h"
  32. #include <mb862xx.h>
  33. #if defined(CONFIG_POST)
  34. #include <post.h>
  35. #endif
  36. /*
  37. * Graphic Device
  38. */
  39. GraphicDevice mb862xx;
  40. /*
  41. * 32MB external RAM - 256K Chip MMIO = 0x1FC0000 ;
  42. */
  43. #define VIDEO_MEM_SIZE 0x01FC0000
  44. #if defined(CONFIG_PCI)
  45. #if defined(CONFIG_VIDEO_CORALP)
  46. static struct pci_device_id supported[] = {
  47. { PCI_VENDOR_ID_FUJITSU, PCI_DEVICE_ID_CORAL_P },
  48. { PCI_VENDOR_ID_FUJITSU, PCI_DEVICE_ID_CORAL_PA },
  49. { }
  50. };
  51. /* Internal clock frequency divider table, index is mode number */
  52. unsigned int fr_div[] = { 0x00000f00, 0x00000900, 0x00000500 };
  53. #endif
  54. #endif
  55. #if defined(CONFIG_VIDEO_CORALP)
  56. #define rd_io in32r
  57. #define wr_io out32r
  58. #else
  59. #define rd_io(addr) in_be32((volatile unsigned*)(addr))
  60. #define wr_io(addr,val) out_be32((volatile unsigned*)(addr), (val))
  61. #endif
  62. #define HOST_RD_REG(off) rd_io((pGD->frameAdrs + 0x01fc0000 + (off)))
  63. #define HOST_WR_REG(off, val) wr_io((pGD->frameAdrs + 0x01fc0000 + (off)), (val))
  64. #define DISP_RD_REG(off) rd_io((pGD->frameAdrs + 0x01fd0000 + (off)))
  65. #define DISP_WR_REG(off, val) wr_io((pGD->frameAdrs + 0x01fd0000 + (off)), (val))
  66. #define DE_RD_REG(off) rd_io((pGD->dprBase + (off)))
  67. #define DE_WR_REG(off, val) wr_io((pGD->dprBase + (off)), (val))
  68. #if defined(CONFIG_VIDEO_CORALP)
  69. #define DE_WR_FIFO(val) wr_io((pGD->dprBase + (0x8400)), (val))
  70. #else
  71. #define DE_WR_FIFO(val) wr_io((pGD->dprBase + (0x04a0)), (val))
  72. #endif
  73. #define L0PAL_RD_REG(idx, val) rd_io((pGD->frameAdrs + 0x01fd0400 + ((idx)<<2)))
  74. #define L0PAL_WR_REG(idx, val) wr_io((pGD->frameAdrs + 0x01fd0400 + ((idx)<<2)), (val))
  75. #define L1PAL_RD_REG(idx, val) rd_io((pGD->frameAdrs + 0x01fd0800 + ((idx)<<2)))
  76. #define L1PAL_WR_REG(idx, val) wr_io((pGD->frameAdrs + 0x01fd0800 + ((idx)<<2)), (val))
  77. #define L2PAL_RD_REG(idx, val) rd_io((pGD->frameAdrs + 0x01fd1000 + ((idx)<<2)))
  78. #define L2PAL_WR_REG(idx, val) wr_io((pGD->frameAdrs + 0x01fd1000 + ((idx)<<2)), (val))
  79. #define L3PAL_RD_REG(idx, val) rd_io((pGD->frameAdrs + 0x01fd1400 + ((idx)<<2)))
  80. #define L3PAL_WR_REG(idx, val) wr_io((pGD->frameAdrs + 0x01fd1400 + ((idx)<<2)), (val))
  81. static void gdc_sw_reset(void)
  82. {
  83. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  84. HOST_WR_REG (0x002c, 0x00000001);
  85. udelay (500);
  86. video_hw_init ();
  87. }
  88. static void de_wait(void)
  89. {
  90. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  91. int lc = 0x10000;
  92. /* Sync with software writes to framebuffer,
  93. try to reset if engine locked */
  94. while (DE_RD_REG (0x0400) & 0x00000131)
  95. if (lc-- < 0) {
  96. gdc_sw_reset ();
  97. printf ("gdc reset done after drawing engine lock...\n");
  98. break;
  99. }
  100. }
  101. static void de_wait_slots(int slots)
  102. {
  103. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  104. int lc = 0x10000;
  105. /* Wait for free fifo slots */
  106. while (DE_RD_REG (0x0408) < slots)
  107. if (lc-- < 0) {
  108. gdc_sw_reset ();
  109. printf ("gdc reset done after drawing engine lock...\n");
  110. break;
  111. }
  112. }
  113. #if !defined(CONFIG_VIDEO_CORALP)
  114. static void board_disp_init(void)
  115. {
  116. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  117. const gdc_regs *regs = board_get_regs ();
  118. while (regs->index) {
  119. DISP_WR_REG (regs->index, regs->value);
  120. regs++;
  121. }
  122. }
  123. #endif
  124. /*
  125. * Init drawing engine
  126. */
  127. static void de_init (void)
  128. {
  129. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  130. int cf = (pGD->gdfBytesPP == 1) ? 0x0000 : 0x8000;
  131. pGD->dprBase = pGD->frameAdrs + 0x01ff0000;
  132. /* Setup mode and fbbase, xres, fg, bg */
  133. de_wait_slots (2);
  134. DE_WR_FIFO (0xf1010108);
  135. DE_WR_FIFO (cf | 0x0300);
  136. DE_WR_REG (0x0440, 0x0000);
  137. DE_WR_REG (0x0444, pGD->winSizeX);
  138. DE_WR_REG (0x0480, 0x0000);
  139. DE_WR_REG (0x0484, 0x0000);
  140. /* Reset clipping */
  141. DE_WR_REG (0x0454, 0x0000);
  142. DE_WR_REG (0x0458, pGD->winSizeX);
  143. DE_WR_REG (0x045c, 0x0000);
  144. DE_WR_REG (0x0460, pGD->winSizeY);
  145. /* Clear framebuffer using drawing engine */
  146. de_wait_slots (3);
  147. DE_WR_FIFO (0x09410000);
  148. DE_WR_FIFO (0x00000000);
  149. DE_WR_FIFO (pGD->winSizeY<<16 | pGD->winSizeX);
  150. /* sync with SW access to framebuffer */
  151. de_wait ();
  152. }
  153. #if defined(CONFIG_VIDEO_CORALP)
  154. unsigned int pci_video_init(void)
  155. {
  156. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  157. pci_dev_t devbusfn;
  158. if ((devbusfn = pci_find_devices(supported, 0)) < 0)
  159. {
  160. printf ("PCI video controller not found!\n");
  161. return 0;
  162. }
  163. /* PCI setup */
  164. pci_write_config_dword (devbusfn, PCI_COMMAND, (PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
  165. pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0, &pGD->frameAdrs);
  166. pGD->frameAdrs = pci_mem_to_phys (devbusfn, pGD->frameAdrs);
  167. if (pGD->frameAdrs == 0) {
  168. printf ("PCI config: failed to get base address\n");
  169. return 0;
  170. }
  171. pGD->pciBase = pGD->frameAdrs;
  172. /* Setup clocks and memory mode for Coral-P Eval. Board */
  173. HOST_WR_REG (0x0038, 0x00090000);
  174. udelay (200);
  175. HOST_WR_REG (0xfffc, 0x11d7fa13);
  176. udelay (100);
  177. return pGD->frameAdrs;
  178. }
  179. unsigned int card_init (void)
  180. {
  181. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  182. unsigned int cf, videomode, div = 0;
  183. unsigned long t1, hsync, vsync;
  184. char *penv;
  185. int tmp, i, bpp;
  186. struct ctfb_res_modes *res_mode;
  187. struct ctfb_res_modes var_mode;
  188. memset (pGD, 0, sizeof (GraphicDevice));
  189. if (!pci_video_init ()) {
  190. return 0;
  191. }
  192. printf ("CoralP\n");
  193. tmp = 0;
  194. videomode = 0x310;
  195. /* get video mode via environment */
  196. if ((penv = getenv ("videomode")) != NULL) {
  197. /* deceide if it is a string */
  198. if (penv[0] <= '9') {
  199. videomode = (int) simple_strtoul (penv, NULL, 16);
  200. tmp = 1;
  201. }
  202. } else {
  203. tmp = 1;
  204. }
  205. if (tmp) {
  206. /* parameter are vesa modes */
  207. /* search params */
  208. for (i = 0; i < VESA_MODES_COUNT; i++) {
  209. if (vesa_modes[i].vesanr == videomode)
  210. break;
  211. }
  212. if (i == VESA_MODES_COUNT) {
  213. printf ("\tno VESA Mode found, switching to mode 0x%x \n", videomode);
  214. i = 0;
  215. }
  216. res_mode =
  217. (struct ctfb_res_modes *) &res_mode_init[vesa_modes[i].resindex];
  218. if (vesa_modes[i].resindex > 2) {
  219. printf ("\tUnsupported resolution, switching to default\n");
  220. bpp = vesa_modes[1].bits_per_pixel;
  221. div = fr_div[1];
  222. }
  223. bpp = vesa_modes[i].bits_per_pixel;
  224. div = fr_div[vesa_modes[i].resindex];
  225. } else {
  226. res_mode = (struct ctfb_res_modes *) &var_mode;
  227. bpp = video_get_params (res_mode, penv);
  228. }
  229. /* calculate hsync and vsync freq (info only) */
  230. t1 = (res_mode->left_margin + res_mode->xres +
  231. res_mode->right_margin + res_mode->hsync_len) / 8;
  232. t1 *= 8;
  233. t1 *= res_mode->pixclock;
  234. t1 /= 1000;
  235. hsync = 1000000000L / t1;
  236. t1 *= (res_mode->upper_margin + res_mode->yres +
  237. res_mode->lower_margin + res_mode->vsync_len);
  238. t1 /= 1000;
  239. vsync = 1000000000L / t1;
  240. /* fill in Graphic device struct */
  241. sprintf (pGD->modeIdent, "%dx%dx%d %ldkHz %ldHz", res_mode->xres,
  242. res_mode->yres, bpp, (hsync / 1000), (vsync / 1000));
  243. printf ("\t%s\n", pGD->modeIdent);
  244. pGD->winSizeX = res_mode->xres;
  245. pGD->winSizeY = res_mode->yres;
  246. pGD->memSize = VIDEO_MEM_SIZE;
  247. switch (bpp) {
  248. case 8:
  249. pGD->gdfIndex = GDF__8BIT_INDEX;
  250. pGD->gdfBytesPP = 1;
  251. break;
  252. case 15:
  253. case 16:
  254. pGD->gdfIndex = GDF_15BIT_555RGB;
  255. pGD->gdfBytesPP = 2;
  256. break;
  257. default:
  258. printf ("\t%d bpp configured, but only 8,15 and 16 supported.\n", bpp);
  259. printf ("\tSwitching back to 15bpp\n");
  260. pGD->gdfIndex = GDF_15BIT_555RGB;
  261. pGD->gdfBytesPP = 2;
  262. }
  263. /* Setup dot clock (internal pll, division rate) */
  264. DISP_WR_REG (0x0100, div);
  265. /* L0 init */
  266. cf = (pGD->gdfBytesPP == 1) ? 0x00000000 : 0x80000000;
  267. DISP_WR_REG (0x0020, ((pGD->winSizeX * pGD->gdfBytesPP)/64)<<16 |
  268. (pGD->winSizeY-1) |
  269. cf);
  270. DISP_WR_REG (0x0024, 0x00000000);
  271. DISP_WR_REG (0x0028, 0x00000000);
  272. DISP_WR_REG (0x002c, 0x00000000);
  273. DISP_WR_REG (0x0110, 0x00000000);
  274. DISP_WR_REG (0x0114, 0x00000000);
  275. DISP_WR_REG (0x0118, (pGD->winSizeY-1)<<16 | pGD->winSizeX);
  276. /* Display timing init */
  277. DISP_WR_REG (0x0004, (pGD->winSizeX+res_mode->left_margin+res_mode->right_margin+res_mode->hsync_len-1)<<16);
  278. DISP_WR_REG (0x0008, (pGD->winSizeX-1) << 16 | (pGD->winSizeX-1));
  279. DISP_WR_REG (0x000c, (res_mode->vsync_len-1)<<24|(res_mode->hsync_len-1)<<16|(pGD->winSizeX+res_mode->right_margin-1));
  280. DISP_WR_REG (0x0010, (pGD->winSizeY+res_mode->lower_margin+res_mode->upper_margin+res_mode->vsync_len-1)<<16);
  281. DISP_WR_REG (0x0014, (pGD->winSizeY-1) << 16 | (pGD->winSizeY+res_mode->lower_margin-1));
  282. DISP_WR_REG (0x0018, 0x00000000);
  283. DISP_WR_REG (0x001c, pGD->winSizeY << 16 | pGD->winSizeX);
  284. /* Display enable, L0 layer */
  285. DISP_WR_REG (0x0100, 0x80010000 | div);
  286. return pGD->frameAdrs;
  287. }
  288. #endif
  289. void *video_hw_init (void)
  290. {
  291. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  292. printf ("Video: Fujitsu ");
  293. memset (pGD, 0, sizeof (GraphicDevice));
  294. #if defined(CONFIG_VIDEO_CORALP)
  295. if (card_init () == 0) {
  296. return (NULL);
  297. }
  298. #else
  299. /* Preliminary init of the onboard graphic controller,
  300. retrieve base address */
  301. if ((pGD->frameAdrs = board_video_init ()) == 0) {
  302. printf ("Controller not found!\n");
  303. return (NULL);
  304. } else
  305. printf("Lime\n");
  306. #endif
  307. de_init ();
  308. #if !defined(CONFIG_VIDEO_CORALP)
  309. board_disp_init();
  310. #endif
  311. #if (defined(CONFIG_LWMON5) || \
  312. defined(CONFIG_SOCRATES)) && !(CONFIG_POST & CONFIG_SYS_POST_SYSMON)
  313. /* Lamp on */
  314. board_backlight_switch (1);
  315. #endif
  316. return pGD;
  317. }
  318. /*
  319. * Set a RGB color in the LUT
  320. */
  321. void video_set_lut (unsigned int index, unsigned char r, unsigned char g, unsigned char b)
  322. {
  323. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  324. L0PAL_WR_REG (index, (r << 16) | (g << 8) | (b));
  325. }
  326. /*
  327. * Drawing engine Fill and BitBlt screen region
  328. */
  329. void video_hw_rectfill (unsigned int bpp, unsigned int dst_x, unsigned int dst_y,
  330. unsigned int dim_x, unsigned int dim_y, unsigned int color)
  331. {
  332. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  333. de_wait_slots (3);
  334. DE_WR_REG (0x0480, color);
  335. DE_WR_FIFO (0x09410000);
  336. DE_WR_FIFO ((dst_y << 16) | dst_x);
  337. DE_WR_FIFO ((dim_y << 16) | dim_x);
  338. de_wait ();
  339. }
  340. void video_hw_bitblt (unsigned int bpp, unsigned int src_x, unsigned int src_y,
  341. unsigned int dst_x, unsigned int dst_y, unsigned int width,
  342. unsigned int height)
  343. {
  344. GraphicDevice *pGD = (GraphicDevice *)&mb862xx;
  345. unsigned int ctrl = 0x0d000000L;
  346. if (src_x >= dst_x && src_y >= dst_y)
  347. ctrl |= 0x00440000L;
  348. else if (src_x >= dst_x && src_y <= dst_y)
  349. ctrl |= 0x00460000L;
  350. else if (src_x <= dst_x && src_y >= dst_y)
  351. ctrl |= 0x00450000L;
  352. else
  353. ctrl |= 0x00470000L;
  354. de_wait_slots (4);
  355. DE_WR_FIFO (ctrl);
  356. DE_WR_FIFO ((src_y << 16) | src_x);
  357. DE_WR_FIFO ((dst_y << 16) | dst_x);
  358. DE_WR_FIFO ((height << 16) | width);
  359. de_wait (); /* sync */
  360. }