bus_vcxk.c 9.6 KB

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