bus_vcxk.c 9.6 KB

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