bus_vcxk.c 11 KB

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