vsp1_wpf.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * vsp1_wpf.c -- R-Car VSP1 Write Pixel Formatter
  3. *
  4. * Copyright (C) 2013-2014 Renesas Electronics Corporation
  5. *
  6. * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/device.h>
  14. #include <media/v4l2-subdev.h>
  15. #include "vsp1.h"
  16. #include "vsp1_dl.h"
  17. #include "vsp1_rwpf.h"
  18. #include "vsp1_video.h"
  19. #define WPF_MAX_WIDTH 2048
  20. #define WPF_MAX_HEIGHT 2048
  21. /* -----------------------------------------------------------------------------
  22. * Device Access
  23. */
  24. static inline void vsp1_wpf_write(struct vsp1_rwpf *wpf, u32 reg, u32 data)
  25. {
  26. vsp1_mod_write(&wpf->entity,
  27. reg + wpf->entity.index * VI6_WPF_OFFSET, data);
  28. }
  29. /* -----------------------------------------------------------------------------
  30. * V4L2 Subdevice Core Operations
  31. */
  32. static int wpf_s_stream(struct v4l2_subdev *subdev, int enable)
  33. {
  34. struct vsp1_pipeline *pipe = to_vsp1_pipeline(&subdev->entity);
  35. struct vsp1_rwpf *wpf = to_rwpf(subdev);
  36. struct vsp1_device *vsp1 = wpf->entity.vsp1;
  37. const struct v4l2_mbus_framefmt *source_format;
  38. const struct v4l2_mbus_framefmt *sink_format;
  39. const struct v4l2_rect *crop;
  40. unsigned int i;
  41. u32 srcrpf = 0;
  42. u32 outfmt = 0;
  43. if (!enable) {
  44. vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), 0);
  45. vsp1_write(vsp1, wpf->entity.index * VI6_WPF_OFFSET +
  46. VI6_WPF_SRCRPF, 0);
  47. return 0;
  48. }
  49. /* Sources. If the pipeline has a single input and BRU is not used,
  50. * configure it as the master layer. Otherwise configure all
  51. * inputs as sub-layers and select the virtual RPF as the master
  52. * layer.
  53. */
  54. for (i = 0; i < vsp1->info->rpf_count; ++i) {
  55. struct vsp1_rwpf *input = pipe->inputs[i];
  56. if (!input)
  57. continue;
  58. srcrpf |= (!pipe->bru && pipe->num_inputs == 1)
  59. ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index)
  60. : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index);
  61. }
  62. if (pipe->bru || pipe->num_inputs > 1)
  63. srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST;
  64. vsp1_wpf_write(wpf, VI6_WPF_SRCRPF, srcrpf);
  65. /* Destination stride. */
  66. if (!pipe->lif) {
  67. struct v4l2_pix_format_mplane *format = &wpf->format;
  68. vsp1_wpf_write(wpf, VI6_WPF_DSTM_STRIDE_Y,
  69. format->plane_fmt[0].bytesperline);
  70. if (format->num_planes > 1)
  71. vsp1_wpf_write(wpf, VI6_WPF_DSTM_STRIDE_C,
  72. format->plane_fmt[1].bytesperline);
  73. }
  74. crop = vsp1_rwpf_get_crop(wpf, wpf->entity.config);
  75. vsp1_wpf_write(wpf, VI6_WPF_HSZCLIP, VI6_WPF_SZCLIP_EN |
  76. (crop->left << VI6_WPF_SZCLIP_OFST_SHIFT) |
  77. (crop->width << VI6_WPF_SZCLIP_SIZE_SHIFT));
  78. vsp1_wpf_write(wpf, VI6_WPF_VSZCLIP, VI6_WPF_SZCLIP_EN |
  79. (crop->top << VI6_WPF_SZCLIP_OFST_SHIFT) |
  80. (crop->height << VI6_WPF_SZCLIP_SIZE_SHIFT));
  81. /* Format */
  82. sink_format = vsp1_entity_get_pad_format(&wpf->entity,
  83. wpf->entity.config,
  84. RWPF_PAD_SINK);
  85. source_format = vsp1_entity_get_pad_format(&wpf->entity,
  86. wpf->entity.config,
  87. RWPF_PAD_SOURCE);
  88. if (!pipe->lif) {
  89. const struct vsp1_format_info *fmtinfo = wpf->fmtinfo;
  90. outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT;
  91. if (fmtinfo->alpha)
  92. outfmt |= VI6_WPF_OUTFMT_PXA;
  93. if (fmtinfo->swap_yc)
  94. outfmt |= VI6_WPF_OUTFMT_SPYCS;
  95. if (fmtinfo->swap_uv)
  96. outfmt |= VI6_WPF_OUTFMT_SPUVS;
  97. vsp1_wpf_write(wpf, VI6_WPF_DSWAP, fmtinfo->swap);
  98. }
  99. if (sink_format->code != source_format->code)
  100. outfmt |= VI6_WPF_OUTFMT_CSC;
  101. outfmt |= wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT;
  102. vsp1_wpf_write(wpf, VI6_WPF_OUTFMT, outfmt);
  103. vsp1_mod_write(&wpf->entity, VI6_DPR_WPF_FPORCH(wpf->entity.index),
  104. VI6_DPR_WPF_FPORCH_FP_WPFN);
  105. vsp1_mod_write(&wpf->entity, VI6_WPF_WRBCK_CTRL, 0);
  106. /* Enable interrupts */
  107. vsp1_write(vsp1, VI6_WPF_IRQ_STA(wpf->entity.index), 0);
  108. vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index),
  109. VI6_WFP_IRQ_ENB_FREE);
  110. return 0;
  111. }
  112. /* -----------------------------------------------------------------------------
  113. * V4L2 Subdevice Operations
  114. */
  115. static struct v4l2_subdev_video_ops wpf_video_ops = {
  116. .s_stream = wpf_s_stream,
  117. };
  118. static struct v4l2_subdev_pad_ops wpf_pad_ops = {
  119. .init_cfg = vsp1_entity_init_cfg,
  120. .enum_mbus_code = vsp1_rwpf_enum_mbus_code,
  121. .enum_frame_size = vsp1_rwpf_enum_frame_size,
  122. .get_fmt = vsp1_rwpf_get_format,
  123. .set_fmt = vsp1_rwpf_set_format,
  124. .get_selection = vsp1_rwpf_get_selection,
  125. .set_selection = vsp1_rwpf_set_selection,
  126. };
  127. static struct v4l2_subdev_ops wpf_ops = {
  128. .video = &wpf_video_ops,
  129. .pad = &wpf_pad_ops,
  130. };
  131. /* -----------------------------------------------------------------------------
  132. * VSP1 Entity Operations
  133. */
  134. static void vsp1_wpf_destroy(struct vsp1_entity *entity)
  135. {
  136. struct vsp1_rwpf *wpf = entity_to_rwpf(entity);
  137. vsp1_dlm_destroy(wpf->dlm);
  138. }
  139. static void wpf_set_memory(struct vsp1_entity *entity)
  140. {
  141. struct vsp1_rwpf *wpf = entity_to_rwpf(entity);
  142. vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_Y, wpf->mem.addr[0]);
  143. vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C0, wpf->mem.addr[1]);
  144. vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C1, wpf->mem.addr[2]);
  145. }
  146. static const struct vsp1_entity_operations wpf_entity_ops = {
  147. .destroy = vsp1_wpf_destroy,
  148. .set_memory = wpf_set_memory,
  149. };
  150. /* -----------------------------------------------------------------------------
  151. * Initialization and Cleanup
  152. */
  153. struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
  154. {
  155. struct vsp1_rwpf *wpf;
  156. char name[6];
  157. int ret;
  158. wpf = devm_kzalloc(vsp1->dev, sizeof(*wpf), GFP_KERNEL);
  159. if (wpf == NULL)
  160. return ERR_PTR(-ENOMEM);
  161. wpf->max_width = WPF_MAX_WIDTH;
  162. wpf->max_height = WPF_MAX_HEIGHT;
  163. wpf->entity.ops = &wpf_entity_ops;
  164. wpf->entity.type = VSP1_ENTITY_WPF;
  165. wpf->entity.index = index;
  166. sprintf(name, "wpf.%u", index);
  167. ret = vsp1_entity_init(vsp1, &wpf->entity, name, 2, &wpf_ops);
  168. if (ret < 0)
  169. return ERR_PTR(ret);
  170. /* Initialize the display list manager. */
  171. wpf->dlm = vsp1_dlm_create(vsp1, index, 4);
  172. if (!wpf->dlm) {
  173. ret = -ENOMEM;
  174. goto error;
  175. }
  176. /* Initialize the control handler. */
  177. ret = vsp1_rwpf_init_ctrls(wpf);
  178. if (ret < 0) {
  179. dev_err(vsp1->dev, "wpf%u: failed to initialize controls\n",
  180. index);
  181. goto error;
  182. }
  183. return wpf;
  184. error:
  185. vsp1_entity_destroy(&wpf->entity);
  186. return ERR_PTR(ret);
  187. }