mixer_grp_layer.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Samsung TV Mixer driver
  3. *
  4. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  5. *
  6. * Tomasz Stanislawski, <t.stanislaws@samsung.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
  10. * by the Free Software Foundiation. either version 2 of the License,
  11. * or (at your option) any later version
  12. */
  13. #include "mixer.h"
  14. #include <media/videobuf2-dma-contig.h>
  15. /* FORMAT DEFINITIONS */
  16. static const struct mxr_format mxr_fb_fmt_rgb565 = {
  17. .name = "RGB565",
  18. .fourcc = V4L2_PIX_FMT_RGB565,
  19. .colorspace = V4L2_COLORSPACE_SRGB,
  20. .num_planes = 1,
  21. .plane = {
  22. { .width = 1, .height = 1, .size = 2 },
  23. },
  24. .num_subframes = 1,
  25. .cookie = 4,
  26. };
  27. static const struct mxr_format mxr_fb_fmt_argb1555 = {
  28. .name = "ARGB1555",
  29. .num_planes = 1,
  30. .fourcc = V4L2_PIX_FMT_RGB555,
  31. .colorspace = V4L2_COLORSPACE_SRGB,
  32. .plane = {
  33. { .width = 1, .height = 1, .size = 2 },
  34. },
  35. .num_subframes = 1,
  36. .cookie = 5,
  37. };
  38. static const struct mxr_format mxr_fb_fmt_argb4444 = {
  39. .name = "ARGB4444",
  40. .num_planes = 1,
  41. .fourcc = V4L2_PIX_FMT_RGB444,
  42. .colorspace = V4L2_COLORSPACE_SRGB,
  43. .plane = {
  44. { .width = 1, .height = 1, .size = 2 },
  45. },
  46. .num_subframes = 1,
  47. .cookie = 6,
  48. };
  49. static const struct mxr_format mxr_fb_fmt_argb8888 = {
  50. .name = "ARGB8888",
  51. .fourcc = V4L2_PIX_FMT_BGR32,
  52. .colorspace = V4L2_COLORSPACE_SRGB,
  53. .num_planes = 1,
  54. .plane = {
  55. { .width = 1, .height = 1, .size = 4 },
  56. },
  57. .num_subframes = 1,
  58. .cookie = 7,
  59. };
  60. static const struct mxr_format *mxr_graph_format[] = {
  61. &mxr_fb_fmt_rgb565,
  62. &mxr_fb_fmt_argb1555,
  63. &mxr_fb_fmt_argb4444,
  64. &mxr_fb_fmt_argb8888,
  65. };
  66. /* AUXILIARY CALLBACKS */
  67. static void mxr_graph_layer_release(struct mxr_layer *layer)
  68. {
  69. mxr_base_layer_unregister(layer);
  70. mxr_base_layer_release(layer);
  71. }
  72. static void mxr_graph_buffer_set(struct mxr_layer *layer,
  73. struct mxr_buffer *buf)
  74. {
  75. dma_addr_t addr = 0;
  76. if (buf)
  77. addr = vb2_dma_contig_plane_dma_addr(&buf->vb, 0);
  78. mxr_reg_graph_buffer(layer->mdev, layer->idx, addr);
  79. }
  80. static void mxr_graph_stream_set(struct mxr_layer *layer, int en)
  81. {
  82. mxr_reg_graph_layer_stream(layer->mdev, layer->idx, en);
  83. }
  84. static void mxr_graph_format_set(struct mxr_layer *layer)
  85. {
  86. mxr_reg_graph_format(layer->mdev, layer->idx,
  87. layer->fmt, &layer->geo);
  88. }
  89. static void mxr_graph_fix_geometry(struct mxr_layer *layer)
  90. {
  91. struct mxr_geometry *geo = &layer->geo;
  92. /* limit to boundary size */
  93. geo->src.full_width = clamp_val(geo->src.full_width, 1, 32767);
  94. geo->src.full_height = clamp_val(geo->src.full_height, 1, 2047);
  95. geo->src.width = clamp_val(geo->src.width, 1, geo->src.full_width);
  96. geo->src.width = min(geo->src.width, 2047U);
  97. /* not possible to crop of Y axis */
  98. geo->src.y_offset = min(geo->src.y_offset, geo->src.full_height - 1);
  99. geo->src.height = geo->src.full_height - geo->src.y_offset;
  100. /* limitting offset */
  101. geo->src.x_offset = min(geo->src.x_offset,
  102. geo->src.full_width - geo->src.width);
  103. /* setting position in output */
  104. geo->dst.width = min(geo->dst.width, geo->dst.full_width);
  105. geo->dst.height = min(geo->dst.height, geo->dst.full_height);
  106. /* Mixer supports only 1x and 2x scaling */
  107. if (geo->dst.width >= 2 * geo->src.width) {
  108. geo->x_ratio = 1;
  109. geo->dst.width = 2 * geo->src.width;
  110. } else {
  111. geo->x_ratio = 0;
  112. geo->dst.width = geo->src.width;
  113. }
  114. if (geo->dst.height >= 2 * geo->src.height) {
  115. geo->y_ratio = 1;
  116. geo->dst.height = 2 * geo->src.height;
  117. } else {
  118. geo->y_ratio = 0;
  119. geo->dst.height = geo->src.height;
  120. }
  121. geo->dst.x_offset = min(geo->dst.x_offset,
  122. geo->dst.full_width - geo->dst.width);
  123. geo->dst.y_offset = min(geo->dst.y_offset,
  124. geo->dst.full_height - geo->dst.height);
  125. }
  126. /* PUBLIC API */
  127. struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
  128. {
  129. struct mxr_layer *layer;
  130. int ret;
  131. struct mxr_layer_ops ops = {
  132. .release = mxr_graph_layer_release,
  133. .buffer_set = mxr_graph_buffer_set,
  134. .stream_set = mxr_graph_stream_set,
  135. .format_set = mxr_graph_format_set,
  136. .fix_geometry = mxr_graph_fix_geometry,
  137. };
  138. char name[32];
  139. sprintf(name, "graph%d", idx);
  140. layer = mxr_base_layer_create(mdev, idx, name, &ops);
  141. if (layer == NULL) {
  142. mxr_err(mdev, "failed to initialize layer(%d) base\n", idx);
  143. goto fail;
  144. }
  145. layer->fmt_array = mxr_graph_format;
  146. layer->fmt_array_size = ARRAY_SIZE(mxr_graph_format);
  147. ret = mxr_base_layer_register(layer);
  148. if (ret)
  149. goto fail_layer;
  150. return layer;
  151. fail_layer:
  152. mxr_base_layer_release(layer);
  153. fail:
  154. return NULL;
  155. }