meson_vpu.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Amlogic Meson Video Processing Unit driver
  4. *
  5. * Copyright (c) 2018 BayLibre, SAS.
  6. * Author: Neil Armstrong <narmstrong@baylibre.com>
  7. */
  8. #include <common.h>
  9. #include <display.h>
  10. #include <dm.h>
  11. #include <efi_loader.h>
  12. #include <fdt_support.h>
  13. #include <linux/sizes.h>
  14. #include <asm/arch/mem.h>
  15. #include <dm/device-internal.h>
  16. #include <dm/uclass-internal.h>
  17. #include "meson_vpu.h"
  18. #include "meson_registers.h"
  19. #include "simplefb_common.h"
  20. #define MESON_VPU_OVERSCAN SZ_64K
  21. /* Static variable for use in meson_vpu_rsv_fb() */
  22. static struct meson_framebuffer {
  23. u64 base;
  24. u64 fb_size;
  25. unsigned int xsize;
  26. unsigned int ysize;
  27. bool is_cvbs;
  28. } meson_fb = { 0 };
  29. bool meson_vpu_is_compatible(struct meson_vpu_priv *priv,
  30. enum vpu_compatible family)
  31. {
  32. enum vpu_compatible compat = dev_get_driver_data(priv->dev);
  33. return compat == family;
  34. }
  35. static int meson_vpu_setup_mode(struct udevice *dev, struct udevice *disp)
  36. {
  37. struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
  38. struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  39. struct display_timing timing;
  40. bool is_cvbs = false;
  41. int ret = 0;
  42. if (disp) {
  43. ret = display_read_timing(disp, &timing);
  44. if (ret) {
  45. debug("%s: Failed to read timings\n", __func__);
  46. goto cvbs;
  47. }
  48. uc_priv->xsize = timing.hactive.typ;
  49. uc_priv->ysize = timing.vactive.typ;
  50. ret = display_enable(disp, 0, &timing);
  51. if (ret)
  52. goto cvbs;
  53. } else {
  54. cvbs:
  55. /* CVBS has a fixed 720x480i (NTSC) and 720x576i (PAL) */
  56. is_cvbs = true;
  57. timing.flags = DISPLAY_FLAGS_INTERLACED;
  58. uc_priv->xsize = 720;
  59. uc_priv->ysize = 576;
  60. }
  61. uc_priv->bpix = VPU_MAX_LOG2_BPP;
  62. meson_fb.is_cvbs = is_cvbs;
  63. meson_fb.xsize = uc_priv->xsize;
  64. meson_fb.ysize = uc_priv->ysize;
  65. /* Move the framebuffer to the end of addressable ram */
  66. meson_fb.fb_size = ALIGN(meson_fb.xsize * meson_fb.ysize *
  67. ((1 << VPU_MAX_LOG2_BPP) / 8) +
  68. MESON_VPU_OVERSCAN, EFI_PAGE_SIZE);
  69. meson_fb.base = gd->bd->bi_dram[0].start +
  70. gd->bd->bi_dram[0].size - meson_fb.fb_size;
  71. /* Override the framebuffer address */
  72. uc_plat->base = meson_fb.base;
  73. meson_vpu_setup_plane(dev, timing.flags & DISPLAY_FLAGS_INTERLACED);
  74. meson_vpu_setup_venc(dev, &timing, is_cvbs);
  75. meson_vpu_setup_vclk(dev, &timing, is_cvbs);
  76. video_set_flush_dcache(dev, 1);
  77. return 0;
  78. }
  79. static const struct udevice_id meson_vpu_ids[] = {
  80. { .compatible = "amlogic,meson-gxbb-vpu", .data = VPU_COMPATIBLE_GXBB },
  81. { .compatible = "amlogic,meson-gxl-vpu", .data = VPU_COMPATIBLE_GXL },
  82. { .compatible = "amlogic,meson-gxm-vpu", .data = VPU_COMPATIBLE_GXM },
  83. { .compatible = "amlogic,meson-g12a-vpu", .data = VPU_COMPATIBLE_G12A },
  84. { }
  85. };
  86. static int meson_vpu_probe(struct udevice *dev)
  87. {
  88. struct meson_vpu_priv *priv = dev_get_priv(dev);
  89. struct udevice *disp;
  90. int ret;
  91. /* Before relocation we don't need to do anything */
  92. if (!(gd->flags & GD_FLG_RELOC))
  93. return 0;
  94. priv->dev = dev;
  95. priv->io_base = dev_remap_addr_index(dev, 0);
  96. if (!priv->io_base)
  97. return -EINVAL;
  98. priv->hhi_base = dev_remap_addr_index(dev, 1);
  99. if (!priv->hhi_base)
  100. return -EINVAL;
  101. priv->dmc_base = dev_remap_addr_index(dev, 2);
  102. if (!priv->dmc_base)
  103. return -EINVAL;
  104. meson_vpu_init(dev);
  105. /* probe the display */
  106. ret = uclass_get_device(UCLASS_DISPLAY, 0, &disp);
  107. return meson_vpu_setup_mode(dev, ret ? NULL : disp);
  108. }
  109. static int meson_vpu_bind(struct udevice *dev)
  110. {
  111. struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
  112. plat->size = VPU_MAX_WIDTH * VPU_MAX_HEIGHT *
  113. (1 << VPU_MAX_LOG2_BPP) / 8;
  114. return 0;
  115. }
  116. #if defined(CONFIG_VIDEO_DT_SIMPLEFB)
  117. static void meson_vpu_setup_simplefb(void *fdt)
  118. {
  119. const char *pipeline = NULL;
  120. u64 mem_start, mem_size;
  121. int offset, ret;
  122. if (meson_fb.is_cvbs)
  123. pipeline = "vpu-cvbs";
  124. else
  125. pipeline = "vpu-hdmi";
  126. offset = meson_simplefb_fdt_match(fdt, pipeline);
  127. if (offset < 0) {
  128. eprintf("Cannot setup simplefb: node not found\n");
  129. /* If simplefb is missing, add it as reserved memory */
  130. meson_board_add_reserved_memory(fdt, meson_fb.base,
  131. meson_fb.fb_size);
  132. return;
  133. }
  134. /*
  135. * SimpleFB will try to iomap the framebuffer, so we can't use
  136. * fdt_add_mem_rsv on the memory area. Instead, the FB is stored
  137. * at the end of the RAM and we strip this portion from the kernel
  138. * allowed region
  139. */
  140. mem_start = gd->bd->bi_dram[0].start;
  141. mem_size = gd->bd->bi_dram[0].size - meson_fb.fb_size;
  142. ret = fdt_fixup_memory_banks(fdt, &mem_start, &mem_size, 1);
  143. if (ret) {
  144. eprintf("Cannot setup simplefb: Error reserving memory\n");
  145. return;
  146. }
  147. ret = fdt_setup_simplefb_node(fdt, offset, meson_fb.base,
  148. meson_fb.xsize, meson_fb.ysize,
  149. meson_fb.xsize * 4, "x8r8g8b8");
  150. if (ret)
  151. eprintf("Cannot setup simplefb: Error setting properties\n");
  152. }
  153. #endif
  154. void meson_vpu_rsv_fb(void *fdt)
  155. {
  156. if (!meson_fb.base || !meson_fb.xsize || !meson_fb.ysize)
  157. return;
  158. #if defined(CONFIG_EFI_LOADER)
  159. efi_add_memory_map(meson_fb.base, meson_fb.fb_size >> EFI_PAGE_SHIFT,
  160. EFI_RESERVED_MEMORY_TYPE, false);
  161. #endif
  162. #if defined(CONFIG_VIDEO_DT_SIMPLEFB)
  163. meson_vpu_setup_simplefb(fdt);
  164. #endif
  165. }
  166. U_BOOT_DRIVER(meson_vpu) = {
  167. .name = "meson_vpu",
  168. .id = UCLASS_VIDEO,
  169. .of_match = meson_vpu_ids,
  170. .probe = meson_vpu_probe,
  171. .bind = meson_vpu_bind,
  172. .priv_auto_alloc_size = sizeof(struct meson_vpu_priv),
  173. .flags = DM_FLAG_PRE_RELOC,
  174. };