console_rotate.c 11 KB

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