fdt_simplefb.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Simplefb device tree support
  4. *
  5. * (C) Copyright 2015
  6. * Stephen Warren <swarren@wwwdotorg.org>
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <lcd.h>
  11. #include <fdt_support.h>
  12. #include <asm/global_data.h>
  13. #include <linux/libfdt.h>
  14. #include <video.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. static int fdt_simplefb_configure_node(void *blob, int off)
  17. {
  18. int xsize, ysize;
  19. int bpix; /* log2 of bits per pixel */
  20. const char *name;
  21. ulong fb_base;
  22. #ifdef CONFIG_DM_VIDEO
  23. struct video_uc_plat *plat;
  24. struct video_priv *uc_priv;
  25. struct udevice *dev;
  26. int ret;
  27. ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
  28. if (ret)
  29. return ret;
  30. uc_priv = dev_get_uclass_priv(dev);
  31. plat = dev_get_uclass_plat(dev);
  32. xsize = uc_priv->xsize;
  33. ysize = uc_priv->ysize;
  34. bpix = uc_priv->bpix;
  35. fb_base = plat->base;
  36. #else
  37. xsize = lcd_get_pixel_width();
  38. ysize = lcd_get_pixel_height();
  39. bpix = LCD_BPP;
  40. fb_base = gd->fb_base;
  41. #endif
  42. switch (bpix) {
  43. case 4: /* VIDEO_BPP16 */
  44. name = "r5g6b5";
  45. break;
  46. case 5: /* VIDEO_BPP32 */
  47. name = "a8r8g8b8";
  48. break;
  49. default:
  50. return -EINVAL;
  51. }
  52. return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
  53. xsize * (1 << bpix) / 8, name);
  54. }
  55. int fdt_simplefb_add_node(void *blob)
  56. {
  57. static const char compat[] = "simple-framebuffer";
  58. static const char disabled[] = "disabled";
  59. int off, ret;
  60. off = fdt_add_subnode(blob, 0, "framebuffer");
  61. if (off < 0)
  62. return -1;
  63. ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
  64. if (ret < 0)
  65. return -1;
  66. ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
  67. if (ret < 0)
  68. return -1;
  69. return fdt_simplefb_configure_node(blob, off);
  70. }
  71. int fdt_simplefb_enable_existing_node(void *blob)
  72. {
  73. int off;
  74. off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
  75. if (off < 0)
  76. return -1;
  77. return fdt_simplefb_configure_node(blob, off);
  78. }
  79. #if CONFIG_IS_ENABLED(DM_VIDEO)
  80. int fdt_simplefb_enable_and_mem_rsv(void *blob)
  81. {
  82. struct fdt_memory mem;
  83. int ret;
  84. /* nothing to do when video is not active */
  85. if (!video_is_active())
  86. return 0;
  87. ret = fdt_simplefb_enable_existing_node(blob);
  88. if (ret)
  89. return ret;
  90. /* nothing to do when the frame buffer is not defined */
  91. if (gd->video_bottom == gd->video_top)
  92. return 0;
  93. /* reserved with no-map tag the video buffer */
  94. mem.start = gd->video_bottom;
  95. mem.end = gd->video_top - 1;
  96. return fdtdec_add_reserved_memory(blob, "framebuffer", &mem, NULL, 0, NULL,
  97. FDTDEC_RESERVED_MEMORY_NO_MAP);
  98. }
  99. #endif