sandbox_sdl.c 2.2 KB

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