sandbox_sdl.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2013 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <fdtdec.h>
  8. #include <lcd.h>
  9. #include <malloc.h>
  10. #include <asm/sdl.h>
  11. #include <asm/u-boot-sandbox.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. enum {
  14. /* Maximum LCD size we support */
  15. LCD_MAX_WIDTH = 1366,
  16. LCD_MAX_HEIGHT = 768,
  17. LCD_MAX_LOG2_BPP = 4, /* 2^4 = 16 bpp */
  18. };
  19. vidinfo_t panel_info;
  20. void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
  21. {
  22. }
  23. void lcd_ctrl_init(void *lcdbase)
  24. {
  25. /*
  26. * Allocate memory to keep BMP color conversion map. This is required
  27. * for 8 bit BMPs only (hence 256 colors). If malloc fails - keep
  28. * going, it is not even clear if displyaing the bitmap will be
  29. * required on the way up.
  30. */
  31. panel_info.cmap = malloc(256 * NBITS(panel_info.vl_bpix) / 8);
  32. }
  33. void lcd_enable(void)
  34. {
  35. if (sandbox_sdl_init_display(panel_info.vl_col, panel_info.vl_row,
  36. panel_info.vl_bpix))
  37. puts("LCD init failed\n");
  38. }
  39. int sandbox_lcd_sdl_early_init(void)
  40. {
  41. const void *blob = gd->fdt_blob;
  42. int xres = LCD_MAX_WIDTH, yres = LCD_MAX_HEIGHT;
  43. int node;
  44. int ret = 0;
  45. /*
  46. * The code in common/lcd.c does not cope with not being able to
  47. * set up a frame buffer. It will just happily keep writing to
  48. * invalid memory. So here we make sure that at least some buffer
  49. * is available even if it actually won't be displayed.
  50. */
  51. node = fdtdec_next_compatible(blob, 0, COMPAT_SANDBOX_LCD_SDL);
  52. if (node >= 0) {
  53. xres = fdtdec_get_int(blob, node, "xres", LCD_MAX_WIDTH);
  54. yres = fdtdec_get_int(blob, node, "yres", LCD_MAX_HEIGHT);
  55. if (xres < 0 || xres > LCD_MAX_WIDTH) {
  56. xres = LCD_MAX_WIDTH;
  57. ret = -EINVAL;
  58. }
  59. if (yres < 0 || yres > LCD_MAX_HEIGHT) {
  60. yres = LCD_MAX_HEIGHT;
  61. ret = -EINVAL;
  62. }
  63. }
  64. panel_info.vl_col = xres;
  65. panel_info.vl_row = yres;
  66. panel_info.vl_bpix = LCD_COLOR16;
  67. return ret;
  68. }