lcd_simplefb.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 lcd_dt_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 lcd_dt_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 lcd_dt_simplefb_configure_node(blob, off);
  70. }
  71. int lcd_dt_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 lcd_dt_simplefb_configure_node(blob, off);
  78. }