diu.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc.
  3. * York Sun <yorksun@freescale.com>
  4. *
  5. * FSL DIU Framebuffer driver
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <asm/io.h>
  28. #include "../../board/freescale/common/pixis.h"
  29. #include "../../board/freescale/common/fsl_diu_fb.h"
  30. #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
  31. #include <devices.h>
  32. #include <video_fb.h>
  33. #endif
  34. #ifdef CONFIG_FSL_DIU_LOGO_BMP
  35. extern unsigned int FSL_Logo_BMP[];
  36. #else
  37. #define FSL_Logo_BMP NULL
  38. #endif
  39. static int xres, yres;
  40. void diu_set_pixel_clock(unsigned int pixclock)
  41. {
  42. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  43. volatile clk512x_t *clk = &immap->clk;
  44. volatile unsigned int *clkdvdr = &clk->scfr[0];
  45. unsigned long speed_ccb, temp, pixval;
  46. speed_ccb = get_bus_freq(0) * 4;
  47. temp = 1000000000/pixclock;
  48. temp *= 1000;
  49. pixval = speed_ccb / temp;
  50. debug("DIU pixval = %lu\n", pixval);
  51. /* Modify PXCLK in GUTS CLKDVDR */
  52. debug("DIU: Current value of CLKDVDR = 0x%08x\n", *clkdvdr);
  53. temp = *clkdvdr & 0xFFFFFF00;
  54. *clkdvdr = temp | (pixval & 0xFF);
  55. debug("DIU: Modified value of CLKDVDR = 0x%08x\n", *clkdvdr);
  56. }
  57. char *valid_bmp(char *addr)
  58. {
  59. unsigned long h_addr;
  60. h_addr = simple_strtoul(addr, NULL, 16);
  61. if (h_addr < CONFIG_SYS_FLASH_BASE ||
  62. h_addr >= (CONFIG_SYS_FLASH_BASE + CONFIG_SYS_FLASH_SIZE - 1)) {
  63. printf("bmp addr %lx is not a valid flash address\n", h_addr);
  64. return 0;
  65. } else if ((*(char *)(h_addr) != 'B') || (*(char *)(h_addr+1) != 'M')) {
  66. printf("bmp addr is not a bmp\n");
  67. return 0;
  68. } else
  69. return (char *)h_addr;
  70. }
  71. int mpc5121_diu_init(void)
  72. {
  73. unsigned int pixel_format;
  74. char *bmp = NULL;
  75. char *bmp_env;
  76. xres = 1024;
  77. yres = 768;
  78. pixel_format = 0x88883316;
  79. debug("mpc5121_diu_init\n");
  80. bmp_env = getenv("diu_bmp_addr");
  81. if (bmp_env) {
  82. bmp = valid_bmp(bmp_env);
  83. }
  84. if (!bmp)
  85. bmp = (char *)FSL_Logo_BMP;
  86. return fsl_diu_init(xres, pixel_format, 0, (unsigned char *)bmp);
  87. }
  88. int mpc5121diu_init_show_bmp(cmd_tbl_t *cmdtp,
  89. int flag, int argc, char *argv[])
  90. {
  91. unsigned int addr;
  92. if (argc < 2) {
  93. cmd_usage(cmdtp);
  94. return 1;
  95. }
  96. if (!strncmp(argv[1], "init", 4)) {
  97. #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
  98. fsl_diu_clear_screen();
  99. drv_video_init();
  100. #else
  101. return mpc5121_diu_init();
  102. #endif
  103. } else {
  104. addr = simple_strtoul(argv[1], NULL, 16);
  105. fsl_diu_clear_screen();
  106. fsl_diu_display_bmp((unsigned char *)addr, 0, 0, 0);
  107. }
  108. return 0;
  109. }
  110. U_BOOT_CMD(
  111. diufb, CONFIG_SYS_MAXARGS, 1, mpc5121diu_init_show_bmp,
  112. "Init or Display BMP file",
  113. "init\n - initialize DIU\n"
  114. "addr\n - display bmp at address 'addr'"
  115. );
  116. #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
  117. /*
  118. * The Graphic Device
  119. */
  120. GraphicDevice ctfb;
  121. void *video_hw_init(void)
  122. {
  123. GraphicDevice *pGD = (GraphicDevice *) &ctfb;
  124. struct fb_info *info;
  125. if (mpc5121_diu_init() < 0)
  126. return;
  127. /* fill in Graphic device struct */
  128. sprintf(pGD->modeIdent, "%dx%dx%d %ldkHz %ldHz",
  129. xres, yres, 32, 64, 60);
  130. pGD->frameAdrs = (unsigned int)fsl_fb_open(&info);
  131. pGD->winSizeX = xres;
  132. pGD->winSizeY = yres - info->logo_height;
  133. pGD->plnSizeX = pGD->winSizeX;
  134. pGD->plnSizeY = pGD->winSizeY;
  135. pGD->gdfBytesPP = 4;
  136. pGD->gdfIndex = GDF_32BIT_X888RGB;
  137. pGD->isaBase = 0;
  138. pGD->pciBase = 0;
  139. pGD->memSize = info->screen_size - info->logo_size;
  140. /* Cursor Start Address */
  141. pGD->dprBase = 0;
  142. pGD->vprBase = 0;
  143. pGD->cprBase = 0;
  144. return (void *)pGD;
  145. }
  146. /**
  147. * Set the LUT
  148. *
  149. * @index: color number
  150. * @r: red
  151. * @b: blue
  152. * @g: green
  153. */
  154. void video_set_lut
  155. (unsigned int index, unsigned char r, unsigned char g, unsigned char b)
  156. {
  157. return;
  158. }
  159. #endif /* defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) */