fdt_simplefb.c 2.5 KB

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