ads5121_diu.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #ifdef CONFIG_FSL_DIU_FB
  29. #include "../freescale/common/pixis.h"
  30. #include "../freescale/common/fsl_diu_fb.h"
  31. #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
  32. #include <devices.h>
  33. #include <video_fb.h>
  34. #endif
  35. #ifdef CONFIG_FSL_DIU_LOGO_BMP
  36. extern unsigned int FSL_Logo_BMP[];
  37. #else
  38. #define FSL_Logo_BMP NULL
  39. #endif
  40. static int xres, yres;
  41. void diu_set_pixel_clock(unsigned int pixclock)
  42. {
  43. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  44. volatile clk512x_t *clk = &immap->clk;
  45. volatile unsigned int *clkdvdr = &clk->scfr[0];
  46. unsigned long speed_ccb, temp, pixval;
  47. speed_ccb = get_bus_freq(0) * 4;
  48. temp = 1000000000/pixclock;
  49. temp *= 1000;
  50. pixval = speed_ccb / temp;
  51. debug("DIU pixval = %lu\n", pixval);
  52. /* Modify PXCLK in GUTS CLKDVDR */
  53. debug("DIU: Current value of CLKDVDR = 0x%08x\n", *clkdvdr);
  54. temp = *clkdvdr & 0xFFFFFF00;
  55. *clkdvdr = temp | (pixval & 0xFF);
  56. debug("DIU: Modified value of CLKDVDR = 0x%08x\n", *clkdvdr);
  57. }
  58. char *valid_bmp(char *addr)
  59. {
  60. unsigned long h_addr;
  61. h_addr = simple_strtoul(addr, NULL, 16);
  62. if (h_addr < CONFIG_SYS_FLASH_BASE ||
  63. h_addr >= (CONFIG_SYS_FLASH_BASE + CONFIG_SYS_FLASH_SIZE - 1)) {
  64. printf("bmp addr %lx is not a valid flash address\n", h_addr);
  65. return 0;
  66. } else if ((*(char *)(h_addr) != 'B') || (*(char *)(h_addr+1) != 'M')) {
  67. printf("bmp addr is not a bmp\n");
  68. return 0;
  69. } else
  70. return (char *)h_addr;
  71. }
  72. int ads5121_diu_init(void)
  73. {
  74. unsigned int pixel_format;
  75. char *bmp = NULL;
  76. char *bmp_env;
  77. xres = 1024;
  78. yres = 768;
  79. pixel_format = 0x88883316;
  80. debug("ads5121_diu_init\n");
  81. bmp_env = getenv("diu_bmp_addr");
  82. if (bmp_env) {
  83. bmp = valid_bmp(bmp_env);
  84. }
  85. if (!bmp)
  86. bmp = FSL_Logo_BMP;
  87. return fsl_diu_init(xres, pixel_format, 0, (unsigned char *)bmp);
  88. }
  89. int ads5121diu_init_show_bmp(cmd_tbl_t *cmdtp,
  90. int flag, int argc, char *argv[])
  91. {
  92. unsigned int addr;
  93. if (argc < 2) {
  94. cmd_usage(cmdtp);
  95. return 1;
  96. }
  97. if (!strncmp(argv[1], "init", 4)) {
  98. #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
  99. fsl_diu_clear_screen();
  100. drv_video_init();
  101. #else
  102. return ads5121_diu_init();
  103. #endif
  104. } else {
  105. addr = simple_strtoul(argv[1], NULL, 16);
  106. fsl_diu_clear_screen();
  107. fsl_diu_display_bmp((unsigned char *)addr, 0, 0, 0);
  108. }
  109. return 0;
  110. }
  111. U_BOOT_CMD(
  112. diufb, CONFIG_SYS_MAXARGS, 1, ads5121diu_init_show_bmp,
  113. "Init or Display BMP file",
  114. "init\n - initialize DIU\n"
  115. "addr\n - display bmp at address 'addr'\n"
  116. );
  117. #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
  118. /*
  119. * The Graphic Device
  120. */
  121. GraphicDevice ctfb;
  122. void *video_hw_init(void)
  123. {
  124. GraphicDevice *pGD = (GraphicDevice *) &ctfb;
  125. struct fb_info *info;
  126. if (ads5121_diu_init() < 0)
  127. return;
  128. /* fill in Graphic device struct */
  129. sprintf(pGD->modeIdent, "%dx%dx%d %ldkHz %ldHz",
  130. xres, yres, 32, 64, 60);
  131. pGD->frameAdrs = (unsigned int)fsl_fb_open(&info);
  132. pGD->winSizeX = xres;
  133. pGD->winSizeY = yres - info->logo_height;
  134. pGD->plnSizeX = pGD->winSizeX;
  135. pGD->plnSizeY = pGD->winSizeY;
  136. pGD->gdfBytesPP = 4;
  137. pGD->gdfIndex = GDF_32BIT_X888RGB;
  138. pGD->isaBase = 0;
  139. pGD->pciBase = 0;
  140. pGD->memSize = info->screen_size - info->logo_size;
  141. /* Cursor Start Address */
  142. pGD->dprBase = 0;
  143. pGD->vprBase = 0;
  144. pGD->cprBase = 0;
  145. return (void *)pGD;
  146. }
  147. /**
  148. * Set the LUT
  149. *
  150. * @index: color number
  151. * @r: red
  152. * @b: blue
  153. * @g: green
  154. */
  155. void video_set_lut
  156. (unsigned int index, unsigned char r, unsigned char g, unsigned char b)
  157. {
  158. return;
  159. }
  160. #endif /* defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) */
  161. #endif /* CONFIG_FSL_DIU_FB */