lcd_simplefb.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <linux/libfdt.h>
  13. #include <video.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static int lcd_dt_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. #ifdef CONFIG_DM_VIDEO
  22. struct video_uc_platdata *plat;
  23. struct video_priv *uc_priv;
  24. struct udevice *dev;
  25. int ret;
  26. ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
  27. if (ret)
  28. return ret;
  29. uc_priv = dev_get_uclass_priv(dev);
  30. plat = dev_get_uclass_platdata(dev);
  31. xsize = uc_priv->xsize;
  32. ysize = uc_priv->ysize;
  33. bpix = uc_priv->bpix;
  34. fb_base = plat->base;
  35. #else
  36. xsize = lcd_get_pixel_width();
  37. ysize = lcd_get_pixel_height();
  38. bpix = LCD_BPP;
  39. fb_base = gd->fb_base;
  40. #endif
  41. switch (bpix) {
  42. case 4: /* VIDEO_BPP16 */
  43. name = "r5g6b5";
  44. break;
  45. case 5: /* VIDEO_BPP32 */
  46. name = "a8r8g8b8";
  47. break;
  48. default:
  49. return -EINVAL;
  50. }
  51. return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
  52. xsize * (1 << bpix) / 8, name);
  53. }
  54. int lcd_dt_simplefb_add_node(void *blob)
  55. {
  56. static const char compat[] = "simple-framebuffer";
  57. static const char disabled[] = "disabled";
  58. int off, ret;
  59. off = fdt_add_subnode(blob, 0, "framebuffer");
  60. if (off < 0)
  61. return -1;
  62. ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
  63. if (ret < 0)
  64. return -1;
  65. ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
  66. if (ret < 0)
  67. return -1;
  68. return lcd_dt_simplefb_configure_node(blob, off);
  69. }
  70. int lcd_dt_simplefb_enable_existing_node(void *blob)
  71. {
  72. int off;
  73. off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
  74. if (off < 0)
  75. return -1;
  76. return lcd_dt_simplefb_configure_node(blob, off);
  77. }