console_rotate.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. * Copyright (c) 2015 Google, Inc
  3. * (C) Copyright 2015
  4. * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <video.h>
  11. #include <video_console.h>
  12. #include <video_font.h> /* Get font data, width and height */
  13. static int console_set_row_1(struct udevice *dev, uint row, int clr)
  14. {
  15. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  16. int pbytes = VNBYTES(vid_priv->bpix);
  17. void *line;
  18. int i, j;
  19. line = vid_priv->fb + vid_priv->line_length -
  20. (row + 1) * VIDEO_FONT_HEIGHT * pbytes;
  21. for (j = 0; j < vid_priv->ysize; j++) {
  22. switch (vid_priv->bpix) {
  23. #ifdef CONFIG_VIDEO_BPP8
  24. case VIDEO_BPP8: {
  25. uint8_t *dst = line;
  26. for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
  27. *dst++ = clr;
  28. break;
  29. }
  30. #endif
  31. #ifdef CONFIG_VIDEO_BPP16
  32. case VIDEO_BPP16: {
  33. uint16_t *dst = line;
  34. for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
  35. *dst++ = clr;
  36. break;
  37. }
  38. #endif
  39. #ifdef CONFIG_VIDEO_BPP32
  40. case VIDEO_BPP32: {
  41. uint32_t *dst = line;
  42. for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
  43. *dst++ = clr;
  44. break;
  45. }
  46. #endif
  47. default:
  48. return -ENOSYS;
  49. }
  50. line += vid_priv->line_length;
  51. }
  52. return 0;
  53. }
  54. static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
  55. uint count)
  56. {
  57. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  58. void *dst;
  59. void *src;
  60. int pbytes = VNBYTES(vid_priv->bpix);
  61. int j;
  62. dst = vid_priv->fb + vid_priv->line_length -
  63. (rowdst + count) * VIDEO_FONT_HEIGHT * pbytes;
  64. src = vid_priv->fb + vid_priv->line_length -
  65. (rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
  66. for (j = 0; j < vid_priv->ysize; j++) {
  67. memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
  68. src += vid_priv->line_length;
  69. dst += vid_priv->line_length;
  70. }
  71. return 0;
  72. }
  73. static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
  74. {
  75. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  76. struct udevice *vid = dev->parent;
  77. struct video_priv *vid_priv = dev_get_uclass_priv(vid);
  78. int pbytes = VNBYTES(vid_priv->bpix);
  79. int i, col;
  80. int mask = 0x80;
  81. void *line;
  82. uchar *pfont = video_fontdata + ch * VIDEO_FONT_HEIGHT;
  83. line = vid_priv->fb + (VID_TO_PIXEL(x_frac) + 1) *
  84. vid_priv->line_length - (y + 1) * pbytes;
  85. if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
  86. return -EAGAIN;
  87. for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
  88. switch (vid_priv->bpix) {
  89. #ifdef CONFIG_VIDEO_BPP8
  90. case VIDEO_BPP8: {
  91. uint8_t *dst = line;
  92. for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
  93. *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
  94. : vid_priv->colour_bg;
  95. }
  96. break;
  97. }
  98. #endif
  99. #ifdef CONFIG_VIDEO_BPP16
  100. case VIDEO_BPP16: {
  101. uint16_t *dst = line;
  102. for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
  103. *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
  104. : vid_priv->colour_bg;
  105. }
  106. break;
  107. }
  108. #endif
  109. #ifdef CONFIG_VIDEO_BPP32
  110. case VIDEO_BPP32: {
  111. uint32_t *dst = line;
  112. for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
  113. *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
  114. : vid_priv->colour_bg;
  115. }
  116. break;
  117. }
  118. #endif
  119. default:
  120. return -ENOSYS;
  121. }
  122. line += vid_priv->line_length;
  123. mask >>= 1;
  124. }
  125. return VID_TO_POS(VIDEO_FONT_WIDTH);
  126. }
  127. static int console_set_row_2(struct udevice *dev, uint row, int clr)
  128. {
  129. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  130. void *line;
  131. int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
  132. int i;
  133. line = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
  134. (row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  135. switch (vid_priv->bpix) {
  136. #ifdef CONFIG_VIDEO_BPP8
  137. case VIDEO_BPP8: {
  138. uint8_t *dst = line;
  139. for (i = 0; i < pixels; i++)
  140. *dst++ = clr;
  141. break;
  142. }
  143. #endif
  144. #ifdef CONFIG_VIDEO_BPP16
  145. case VIDEO_BPP16: {
  146. uint16_t *dst = line;
  147. for (i = 0; i < pixels; i++)
  148. *dst++ = clr;
  149. break;
  150. }
  151. #endif
  152. #ifdef CONFIG_VIDEO_BPP32
  153. case VIDEO_BPP32: {
  154. uint32_t *dst = line;
  155. for (i = 0; i < pixels; i++)
  156. *dst++ = clr;
  157. break;
  158. }
  159. #endif
  160. default:
  161. return -ENOSYS;
  162. }
  163. return 0;
  164. }
  165. static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
  166. uint count)
  167. {
  168. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  169. void *dst;
  170. void *src;
  171. void *end;
  172. end = vid_priv->fb + vid_priv->ysize * vid_priv->line_length;
  173. dst = end - (rowdst + count) * VIDEO_FONT_HEIGHT *
  174. vid_priv->line_length;
  175. src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
  176. vid_priv->line_length;
  177. memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
  178. return 0;
  179. }
  180. static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
  181. {
  182. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  183. struct udevice *vid = dev->parent;
  184. struct video_priv *vid_priv = dev_get_uclass_priv(vid);
  185. int i, row;
  186. void *line;
  187. if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
  188. return -EAGAIN;
  189. line = vid_priv->fb + (vid_priv->ysize - y - 1) *
  190. vid_priv->line_length +
  191. (vid_priv->xsize - VID_TO_PIXEL(x_frac) -
  192. VIDEO_FONT_WIDTH - 1) * VNBYTES(vid_priv->bpix);
  193. for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
  194. uchar bits = video_fontdata[ch * VIDEO_FONT_HEIGHT + row];
  195. switch (vid_priv->bpix) {
  196. #ifdef CONFIG_VIDEO_BPP8
  197. case VIDEO_BPP8: {
  198. uint8_t *dst = line;
  199. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  200. *dst-- = (bits & 0x80) ? vid_priv->colour_fg
  201. : vid_priv->colour_bg;
  202. bits <<= 1;
  203. }
  204. break;
  205. }
  206. #endif
  207. #ifdef CONFIG_VIDEO_BPP16
  208. case VIDEO_BPP16: {
  209. uint16_t *dst = line;
  210. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  211. *dst-- = (bits & 0x80) ? vid_priv->colour_fg
  212. : vid_priv->colour_bg;
  213. bits <<= 1;
  214. }
  215. break;
  216. }
  217. #endif
  218. #ifdef CONFIG_VIDEO_BPP32
  219. case VIDEO_BPP32: {
  220. uint32_t *dst = line;
  221. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  222. *dst-- = (bits & 0x80) ? vid_priv->colour_fg
  223. : vid_priv->colour_bg;
  224. bits <<= 1;
  225. }
  226. break;
  227. }
  228. #endif
  229. default:
  230. return -ENOSYS;
  231. }
  232. line -= vid_priv->line_length;
  233. }
  234. return VID_TO_POS(VIDEO_FONT_WIDTH);
  235. }
  236. static int console_set_row_3(struct udevice *dev, uint row, int clr)
  237. {
  238. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  239. int pbytes = VNBYTES(vid_priv->bpix);
  240. void *line;
  241. int i, j;
  242. line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
  243. for (j = 0; j < vid_priv->ysize; j++) {
  244. switch (vid_priv->bpix) {
  245. #ifdef CONFIG_VIDEO_BPP8
  246. case VIDEO_BPP8: {
  247. uint8_t *dst = line;
  248. for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
  249. *dst++ = clr;
  250. break;
  251. }
  252. #endif
  253. #ifdef CONFIG_VIDEO_BPP16
  254. case VIDEO_BPP16: {
  255. uint16_t *dst = line;
  256. for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
  257. *dst++ = clr;
  258. break;
  259. }
  260. #endif
  261. #ifdef CONFIG_VIDEO_BPP32
  262. case VIDEO_BPP32: {
  263. uint32_t *dst = line;
  264. for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
  265. *dst++ = clr;
  266. break;
  267. }
  268. #endif
  269. default:
  270. return -ENOSYS;
  271. }
  272. line += vid_priv->line_length;
  273. }
  274. return 0;
  275. }
  276. static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
  277. uint count)
  278. {
  279. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  280. void *dst;
  281. void *src;
  282. int pbytes = VNBYTES(vid_priv->bpix);
  283. int j;
  284. dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
  285. src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
  286. for (j = 0; j < vid_priv->ysize; j++) {
  287. memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
  288. src += vid_priv->line_length;
  289. dst += vid_priv->line_length;
  290. }
  291. return 0;
  292. }
  293. static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
  294. {
  295. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  296. struct udevice *vid = dev->parent;
  297. struct video_priv *vid_priv = dev_get_uclass_priv(vid);
  298. int pbytes = VNBYTES(vid_priv->bpix);
  299. int i, col;
  300. int mask = 0x80;
  301. void *line = vid_priv->fb +
  302. (vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1) *
  303. vid_priv->line_length + y * pbytes;
  304. uchar *pfont = video_fontdata + ch * VIDEO_FONT_HEIGHT;
  305. if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
  306. return -EAGAIN;
  307. for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
  308. switch (vid_priv->bpix) {
  309. #ifdef CONFIG_VIDEO_BPP8
  310. case VIDEO_BPP8: {
  311. uint8_t *dst = line;
  312. for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
  313. *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
  314. : vid_priv->colour_bg;
  315. }
  316. break;
  317. }
  318. #endif
  319. #ifdef CONFIG_VIDEO_BPP16
  320. case VIDEO_BPP16: {
  321. uint16_t *dst = line;
  322. for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
  323. *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
  324. : vid_priv->colour_bg;
  325. }
  326. break;
  327. }
  328. #endif
  329. #ifdef CONFIG_VIDEO_BPP32
  330. case VIDEO_BPP32: {
  331. uint32_t *dst = line;
  332. for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
  333. *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
  334. : vid_priv->colour_bg;
  335. }
  336. break;
  337. }
  338. #endif
  339. default:
  340. return -ENOSYS;
  341. }
  342. line -= vid_priv->line_length;
  343. mask >>= 1;
  344. }
  345. return VID_TO_POS(VIDEO_FONT_WIDTH);
  346. }
  347. static int console_probe_2(struct udevice *dev)
  348. {
  349. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  350. struct udevice *vid_dev = dev->parent;
  351. struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
  352. vc_priv->x_charsize = VIDEO_FONT_WIDTH;
  353. vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
  354. vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
  355. vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
  356. return 0;
  357. }
  358. static int console_probe_1_3(struct udevice *dev)
  359. {
  360. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  361. struct udevice *vid_dev = dev->parent;
  362. struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
  363. vc_priv->x_charsize = VIDEO_FONT_WIDTH;
  364. vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
  365. vc_priv->cols = vid_priv->ysize / VIDEO_FONT_WIDTH;
  366. vc_priv->rows = vid_priv->xsize / VIDEO_FONT_HEIGHT;
  367. vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
  368. return 0;
  369. }
  370. struct vidconsole_ops console_ops_1 = {
  371. .putc_xy = console_putc_xy_1,
  372. .move_rows = console_move_rows_1,
  373. .set_row = console_set_row_1,
  374. };
  375. struct vidconsole_ops console_ops_2 = {
  376. .putc_xy = console_putc_xy_2,
  377. .move_rows = console_move_rows_2,
  378. .set_row = console_set_row_2,
  379. };
  380. struct vidconsole_ops console_ops_3 = {
  381. .putc_xy = console_putc_xy_3,
  382. .move_rows = console_move_rows_3,
  383. .set_row = console_set_row_3,
  384. };
  385. U_BOOT_DRIVER(vidconsole_1) = {
  386. .name = "vidconsole1",
  387. .id = UCLASS_VIDEO_CONSOLE,
  388. .ops = &console_ops_1,
  389. .probe = console_probe_1_3,
  390. };
  391. U_BOOT_DRIVER(vidconsole_2) = {
  392. .name = "vidconsole2",
  393. .id = UCLASS_VIDEO_CONSOLE,
  394. .ops = &console_ops_2,
  395. .probe = console_probe_2,
  396. };
  397. U_BOOT_DRIVER(vidconsole_3) = {
  398. .name = "vidconsole3",
  399. .id = UCLASS_VIDEO_CONSOLE,
  400. .ops = &console_ops_3,
  401. .probe = console_probe_1_3,
  402. };