bus_vcxk.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * (C) Copyright 2005-2009
  3. * Jens Scharsig @ BuS Elektronik GmbH & Co. KG, <esw@bus-elektronik.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. #include <common.h>
  24. #include <bmp_layout.h>
  25. #include <asm/io.h>
  26. vu_char *vcxk_bws = ((vu_char *) (CONFIG_SYS_VCXK_BASE));
  27. vu_short *vcxk_bws_word = ((vu_short *)(CONFIG_SYS_VCXK_BASE));
  28. vu_long *vcxk_bws_long = ((vu_long *) (CONFIG_SYS_VCXK_BASE));
  29. #ifdef CONFIG_AT91RM9200
  30. #include <asm/arch/hardware.h>
  31. #ifndef VCBITMASK
  32. #define VCBITMASK(bitno) (0x0001 << (bitno % 16))
  33. #endif
  34. #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
  35. ((AT91PS_PIO) PORT)->PIO_PER = PIN; \
  36. ((AT91PS_PIO) PORT)->DDR = PIN; \
  37. ((AT91PS_PIO) PORT)->PIO_MDDR = PIN; \
  38. if (!I0O1) ((AT91PS_PIO) PORT)->PIO_PPUER = PIN;
  39. #define VCXK_SET_PIN(PORT, PIN) ((AT91PS_PIO) PORT)->PIO_SODR = PIN;
  40. #define VCXK_CLR_PIN(PORT, PIN) ((AT91PS_PIO) PORT)->PIO_CODR = PIN;
  41. #define VCXK_ACKNOWLEDGE \
  42. (!(((AT91PS_PIO) CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT)->\
  43. PIO_PDSR & CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
  44. #elif defined(CONFIG_MCF52x2)
  45. #include <asm/m5282.h>
  46. #ifndef VCBITMASK
  47. #define VCBITMASK(bitno) (0x8000 >> (bitno % 16))
  48. #endif
  49. #define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
  50. if (I0O1) DDR |= PIN; else DDR &= ~PIN;
  51. #define VCXK_SET_PIN(PORT, PIN) PORT |= PIN;
  52. #define VCXK_CLR_PIN(PORT, PIN) PORT &= ~PIN;
  53. #define VCXK_ACKNOWLEDGE \
  54. (!(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT & \
  55. CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))
  56. #else
  57. #error no vcxk support for selected ARCH
  58. #endif
  59. #define VCXK_DISABLE\
  60. VCXK_SET_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
  61. #define VCXK_ENABLE\
  62. VCXK_CLR_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
  63. #ifndef CONFIG_SYS_VCXK_DOUBLEBUFFERED
  64. #define VCXK_BWS(x, data) vcxk_bws[x] = data;
  65. #define VCXK_BWS_WORD_SET(x, mask) vcxk_bws_word[x] |= mask;
  66. #define VCXK_BWS_WORD_CLEAR(x, mask) vcxk_bws_word[x] &= ~mask;
  67. #define VCXK_BWS_LONG(x, data) vcxk_bws_long[x] = data;
  68. #else
  69. u_char double_bws[16384];
  70. u_short *double_bws_word;
  71. u_long *double_bws_long;
  72. #define VCXK_BWS(x,data) \
  73. double_bws[x] = data; vcxk_bws[x] = data;
  74. #define VCXK_BWS_WORD_SET(x,mask) \
  75. double_bws_word[x] |= mask; \
  76. vcxk_bws_word[x] = double_bws_word[x];
  77. #define VCXK_BWS_WORD_CLEAR(x,mask) \
  78. double_bws_word[x] &= ~mask; \
  79. vcxk_bws_word[x] = double_bws_word[x];
  80. #define VCXK_BWS_LONG(x,data) \
  81. double_bws_long[x] = data; vcxk_bws_long[x] = data;
  82. #endif
  83. #define VC4K16_Bright1 vcxk_bws_word[0x20004 / 2]
  84. #define VC4K16_Bright2 vcxk_bws_word[0x20006 / 2]
  85. #define VC2K_Bright vcxk_bws[0x8000]
  86. #define VC8K_BrightH vcxk_bws[0xC000]
  87. #define VC8K_BrightL vcxk_bws[0xC001]
  88. vu_char VC4K16;
  89. u_long display_width;
  90. u_long display_height;
  91. u_long display_bwidth;
  92. ulong search_vcxk_driver(void);
  93. void vcxk_cls(void);
  94. void vcxk_setbrightness(unsigned int side, short brightness);
  95. int vcxk_request(void);
  96. int vcxk_acknowledge_wait(void);
  97. void vcxk_clear(void);
  98. /*
  99. ****f* bus_vcxk/vcxk_init
  100. * FUNCTION
  101. * initialalize Video Controller
  102. * PARAMETERS
  103. * width visible display width in pixel
  104. * height visible display height in pixel
  105. ***
  106. */
  107. int vcxk_init(unsigned long width, unsigned long height)
  108. {
  109. #ifdef CONFIG_SYS_VCXK_RESET_PORT
  110. VCXK_INIT_PIN(CONFIG_SYS_VCXK_RESET_PORT,
  111. CONFIG_SYS_VCXK_RESET_PIN, CONFIG_SYS_VCXK_RESET_DDR, 1)
  112. VCXK_SET_PIN(CONFIG_SYS_VCXK_RESET_PORT, CONFIG_SYS_VCXK_RESET_PIN);
  113. #endif
  114. #ifdef CONFIG_SYS_VCXK_DOUBLEBUFFERED
  115. double_bws_word = (u_short *)double_bws;
  116. double_bws_long = (u_long *)double_bws;
  117. debug("%lx %lx %lx \n", double_bws, double_bws_word, double_bws_long);
  118. #endif
  119. display_width = width;
  120. display_height = height;
  121. #if (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 4)
  122. display_bwidth = ((width + 31) / 8) & ~0x3;
  123. #elif (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 2)
  124. display_bwidth = ((width + 15) / 8) & ~0x1;
  125. #else
  126. #error CONFIG_SYS_VCXK_DEFAULT_LINEALIGN is invalid
  127. #endif
  128. debug("linesize ((%d + 15) / 8 & ~0x1) = %d\n",
  129. display_width, display_bwidth);
  130. #ifdef CONFIG_SYS_VCXK_AUTODETECT
  131. VC4K16 = 0;
  132. vcxk_bws_long[1] = 0x0;
  133. vcxk_bws_long[1] = 0x55AAAA55;
  134. vcxk_bws_long[5] = 0x0;
  135. if (vcxk_bws_long[1] == 0x55AAAA55)
  136. VC4K16 = 1;
  137. #else
  138. VC4K16 = 1;
  139. debug("No autodetect: use vc4k\n");
  140. #endif
  141. VCXK_INIT_PIN(CONFIG_SYS_VCXK_INVERT_PORT,
  142. CONFIG_SYS_VCXK_INVERT_PIN, CONFIG_SYS_VCXK_INVERT_DDR, 1)
  143. VCXK_SET_PIN(CONFIG_SYS_VCXK_INVERT_PORT, CONFIG_SYS_VCXK_INVERT_PIN)
  144. VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT, CONFIG_SYS_VCXK_REQUEST_PIN);
  145. VCXK_INIT_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
  146. CONFIG_SYS_VCXK_REQUEST_PIN, CONFIG_SYS_VCXK_REQUEST_DDR, 1)
  147. VCXK_INIT_PIN(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT,
  148. CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN,
  149. CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR, 0)
  150. VCXK_DISABLE;
  151. VCXK_INIT_PIN(CONFIG_SYS_VCXK_ENABLE_PORT,
  152. CONFIG_SYS_VCXK_ENABLE_PIN, CONFIG_SYS_VCXK_ENABLE_DDR, 1)
  153. vcxk_cls();
  154. vcxk_cls(); /* clear second/hidden page */
  155. vcxk_setbrightness(3, 1000);
  156. VCXK_ENABLE;
  157. return 1;
  158. }
  159. /*
  160. ****f* bus_vcxk/vcxk_setpixel
  161. * FUNCTION
  162. * set the pixel[x,y] with the given color
  163. * PARAMETER
  164. * x pixel colum
  165. * y pixel row
  166. * color <0x40 off/black
  167. * >0x40 on
  168. ***
  169. */
  170. void vcxk_setpixel(int x, int y, unsigned long color)
  171. {
  172. vu_short dataptr;
  173. if ((x < display_width) && (y < display_height)) {
  174. dataptr = ((x / 16)) + (y * (display_bwidth >> 1));
  175. color = ((color >> 16) & 0xFF) |
  176. ((color >> 8) & 0xFF) | (color & 0xFF);
  177. if (color > 0x40) {
  178. VCXK_BWS_WORD_SET(dataptr, VCBITMASK(x));
  179. } else {
  180. VCXK_BWS_WORD_CLEAR(dataptr, VCBITMASK(x));
  181. }
  182. }
  183. }
  184. /*
  185. ****f* bus_vcxk/vcxk_loadimage
  186. * FUNCTION
  187. * copies a binary image to display memory
  188. ***
  189. */
  190. void vcxk_loadimage(ulong source)
  191. {
  192. int cnt;
  193. vcxk_acknowledge_wait();
  194. if (VC4K16) {
  195. for (cnt = 0; cnt < (16384 / 4); cnt++) {
  196. VCXK_BWS_LONG(cnt, (*(ulong *) source));
  197. source = source + 4;
  198. }
  199. } else {
  200. for (cnt = 0; cnt < 16384; cnt++) {
  201. VCXK_BWS_LONG(cnt*2, (*(vu_char *) source));
  202. source++;
  203. }
  204. }
  205. vcxk_request();
  206. }
  207. /*
  208. ****f* bus_vcxk/vcxk_cls
  209. * FUNCTION
  210. * clear the display
  211. ***
  212. */
  213. void vcxk_cls(void)
  214. {
  215. vcxk_acknowledge_wait();
  216. vcxk_clear();
  217. vcxk_request();
  218. }
  219. /*
  220. ****f* bus_vcxk/vcxk_clear(void)
  221. * FUNCTION
  222. * clear the display memory
  223. ***
  224. */
  225. void vcxk_clear(void)
  226. {
  227. int cnt;
  228. for (cnt = 0; cnt < (16384 / 4); cnt++) {
  229. VCXK_BWS_LONG(cnt, 0)
  230. }
  231. }
  232. /*
  233. ****f* bus_vcxk/vcxk_setbrightness
  234. * FUNCTION
  235. * set the display brightness
  236. * PARAMETER
  237. * side 1 set front side brightness
  238. * 2 set back side brightness
  239. * 3 set brightness for both sides
  240. * brightness 0..1000
  241. ***
  242. */
  243. void vcxk_setbrightness(unsigned int side, short brightness)
  244. {
  245. if (VC4K16) {
  246. if ((side == 0) || (side & 0x1))
  247. VC4K16_Bright1 = brightness + 23;
  248. if ((side == 0) || (side & 0x2))
  249. VC4K16_Bright2 = brightness + 23;
  250. } else {
  251. VC2K_Bright = (brightness >> 4) + 2;
  252. VC8K_BrightH = (brightness + 23) >> 8;
  253. VC8K_BrightL = (brightness + 23) & 0xFF;
  254. }
  255. }
  256. /*
  257. ****f* bus_vcxk/vcxk_request
  258. * FUNCTION
  259. * requests viewing of display memory
  260. ***
  261. */
  262. int vcxk_request(void)
  263. {
  264. VCXK_CLR_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
  265. CONFIG_SYS_VCXK_REQUEST_PIN)
  266. VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
  267. CONFIG_SYS_VCXK_REQUEST_PIN);
  268. return 1;
  269. }
  270. /*
  271. ****f* bus_vcxk/vcxk_acknowledge_wait
  272. * FUNCTION
  273. * wait for acknowledge viewing requests
  274. ***
  275. */
  276. int vcxk_acknowledge_wait(void)
  277. {
  278. while (VCXK_ACKNOWLEDGE)
  279. ;
  280. return 1;
  281. }
  282. /*
  283. ****f* bus_vcxk/vcxk_draw_mono
  284. * FUNCTION
  285. * copies a monochrom bitmap (BMP-Format) from given memory
  286. * PARAMETER
  287. * dataptr pointer to bitmap
  288. * x output bitmap @ columne
  289. * y output bitmap @ row
  290. ***
  291. */
  292. void vcxk_draw_mono(unsigned char *dataptr, unsigned long linewidth,
  293. unsigned long cp_width, unsigned long cp_height)
  294. {
  295. unsigned char *lineptr;
  296. unsigned long xcnt, ycnt;
  297. for (ycnt = cp_height; ycnt > 0; ycnt--) {
  298. lineptr = dataptr;
  299. for (xcnt = 0; xcnt < cp_width; xcnt++) {
  300. if ((*lineptr << (xcnt % 8)) & 0x80)
  301. vcxk_setpixel(xcnt, ycnt - 1, 0xFFFFFF);
  302. else
  303. vcxk_setpixel(xcnt, ycnt-1, 0);
  304. if ((xcnt % 8) == 7)
  305. lineptr++;
  306. } /* endfor xcnt */
  307. dataptr = dataptr + linewidth;
  308. } /* endfor ycnt */
  309. }
  310. /*
  311. ****f* bus_vcxk/vcxk_display_bitmap
  312. * FUNCTION
  313. * copies a bitmap (BMP-Format) to the given position
  314. * PARAMETER
  315. * addr pointer to bitmap
  316. * x output bitmap @ columne
  317. * y output bitmap @ row
  318. ***
  319. */
  320. int vcxk_display_bitmap(ulong addr, int x, int y)
  321. {
  322. bmp_image_t *bmp;
  323. unsigned long width;
  324. unsigned long height;
  325. unsigned long bpp;
  326. unsigned long compression;
  327. unsigned long lw;
  328. unsigned long c_width;
  329. unsigned long c_height;
  330. unsigned char *dataptr;
  331. unsigned char *lineptr;
  332. bmp = (bmp_image_t *) addr;
  333. if ((bmp->header.signature[0] == 'B') &&
  334. (bmp->header.signature[1] == 'M')) {
  335. compression = le32_to_cpu(bmp->header.compression);
  336. width = le32_to_cpu(bmp->header.width);
  337. height = le32_to_cpu(bmp->header.height);
  338. bpp = le16_to_cpu(bmp->header.bit_count);
  339. dataptr = (unsigned char *) bmp +
  340. le32_to_cpu(bmp->header.data_offset);
  341. if (display_width < (width + x))
  342. c_width = display_width - x;
  343. else
  344. c_width = width;
  345. if (display_height < (height + y))
  346. c_height = display_height - y;
  347. else
  348. c_height = height;
  349. lw = (((width + 7) / 8) + 3) & ~0x3;
  350. if (c_height < height)
  351. dataptr = dataptr + lw * (height - c_height);
  352. switch (bpp) {
  353. case 1:
  354. vcxk_draw_mono(dataptr, lw, c_width, c_height);
  355. break;
  356. default:
  357. printf("Error: %ld bit per pixel "
  358. "not supported by VCxK\n", bpp);
  359. return 0;
  360. }
  361. } else {
  362. printf("Error: no valid bmp at %lx\n", (ulong) bmp);
  363. return 0;
  364. }
  365. return 1;
  366. }
  367. /*
  368. ****f* bus_vcxk/video_display_bitmap
  369. ***
  370. */
  371. int video_display_bitmap(ulong addr, int x, int y)
  372. {
  373. vcxk_acknowledge_wait();
  374. if (vcxk_display_bitmap(addr, x, y)) {
  375. vcxk_request();
  376. return 0;
  377. }
  378. return 1;
  379. }
  380. /* EOF */