sandbox_sdl.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2013 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <fdtdec.h>
  8. #include <log.h>
  9. #include <video.h>
  10. #include <asm/global_data.h>
  11. #include <asm/sdl.h>
  12. #include <asm/state.h>
  13. #include <asm/u-boot-sandbox.h>
  14. #include <dm/test.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. enum {
  17. /* Default LCD size we support */
  18. LCD_MAX_WIDTH = 1366,
  19. LCD_MAX_HEIGHT = 768,
  20. };
  21. static int sandbox_sdl_probe(struct udevice *dev)
  22. {
  23. struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
  24. struct sandbox_sdl_plat *plat = dev_get_plat(dev);
  25. struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  26. struct sandbox_state *state = state_get_current();
  27. int ret;
  28. ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
  29. state->double_lcd);
  30. if (ret) {
  31. puts("LCD init failed\n");
  32. return ret;
  33. }
  34. uc_priv->xsize = plat->xres;
  35. uc_priv->ysize = plat->yres;
  36. uc_priv->bpix = plat->bpix;
  37. uc_priv->rot = plat->rot;
  38. uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
  39. uc_priv->font_size = plat->font_size;
  40. if (IS_ENABLED(CONFIG_VIDEO_COPY))
  41. uc_plat->copy_base = uc_plat->base - uc_plat->size / 2;
  42. return 0;
  43. }
  44. static int sandbox_sdl_bind(struct udevice *dev)
  45. {
  46. struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
  47. struct sandbox_sdl_plat *plat = dev_get_plat(dev);
  48. int ret = 0;
  49. plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH);
  50. plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT);
  51. plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
  52. plat->rot = dev_read_u32_default(dev, "rotate", 0);
  53. uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
  54. /* Allow space for two buffers, the lower one being the copy buffer */
  55. log_debug("Frame buffer size %x\n", uc_plat->size);
  56. if (IS_ENABLED(CONFIG_VIDEO_COPY))
  57. uc_plat->size *= 2;
  58. return ret;
  59. }
  60. static const struct udevice_id sandbox_sdl_ids[] = {
  61. { .compatible = "sandbox,lcd-sdl" },
  62. { }
  63. };
  64. U_BOOT_DRIVER(sandbox_lcd_sdl) = {
  65. .name = "sandbox_lcd_sdl",
  66. .id = UCLASS_VIDEO,
  67. .of_match = sandbox_sdl_ids,
  68. .bind = sandbox_sdl_bind,
  69. .probe = sandbox_sdl_probe,
  70. .plat_auto = sizeof(struct sandbox_sdl_plat),
  71. };