vsp1_rwpf.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * vsp1_rwpf.c -- R-Car VSP1 Read and Write Pixel Formatters
  3. *
  4. * Copyright (C) 2013 Renesas 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 <media/v4l2-subdev.h>
  14. #include "vsp1.h"
  15. #include "vsp1_rwpf.h"
  16. #include "vsp1_video.h"
  17. #define RWPF_MIN_WIDTH 1
  18. #define RWPF_MIN_HEIGHT 1
  19. /* -----------------------------------------------------------------------------
  20. * V4L2 Subdevice Pad Operations
  21. */
  22. int vsp1_rwpf_enum_mbus_code(struct v4l2_subdev *subdev,
  23. struct v4l2_subdev_fh *fh,
  24. struct v4l2_subdev_mbus_code_enum *code)
  25. {
  26. static const unsigned int codes[] = {
  27. V4L2_MBUS_FMT_ARGB8888_1X32,
  28. V4L2_MBUS_FMT_AYUV8_1X32,
  29. };
  30. if (code->index >= ARRAY_SIZE(codes))
  31. return -EINVAL;
  32. code->code = codes[code->index];
  33. return 0;
  34. }
  35. int vsp1_rwpf_enum_frame_size(struct v4l2_subdev *subdev,
  36. struct v4l2_subdev_fh *fh,
  37. struct v4l2_subdev_frame_size_enum *fse)
  38. {
  39. struct vsp1_rwpf *rwpf = to_rwpf(subdev);
  40. struct v4l2_mbus_framefmt *format;
  41. format = v4l2_subdev_get_try_format(fh, fse->pad);
  42. if (fse->index || fse->code != format->code)
  43. return -EINVAL;
  44. if (fse->pad == RWPF_PAD_SINK) {
  45. fse->min_width = RWPF_MIN_WIDTH;
  46. fse->max_width = rwpf->max_width;
  47. fse->min_height = RWPF_MIN_HEIGHT;
  48. fse->max_height = rwpf->max_height;
  49. } else {
  50. /* The size on the source pad are fixed and always identical to
  51. * the size on the sink pad.
  52. */
  53. fse->min_width = format->width;
  54. fse->max_width = format->width;
  55. fse->min_height = format->height;
  56. fse->max_height = format->height;
  57. }
  58. return 0;
  59. }
  60. int vsp1_rwpf_get_format(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh,
  61. struct v4l2_subdev_format *fmt)
  62. {
  63. struct vsp1_rwpf *rwpf = to_rwpf(subdev);
  64. fmt->format = *vsp1_entity_get_pad_format(&rwpf->entity, fh, fmt->pad,
  65. fmt->which);
  66. return 0;
  67. }
  68. int vsp1_rwpf_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh,
  69. struct v4l2_subdev_format *fmt)
  70. {
  71. struct vsp1_rwpf *rwpf = to_rwpf(subdev);
  72. struct v4l2_mbus_framefmt *format;
  73. /* Default to YUV if the requested format is not supported. */
  74. if (fmt->format.code != V4L2_MBUS_FMT_ARGB8888_1X32 &&
  75. fmt->format.code != V4L2_MBUS_FMT_AYUV8_1X32)
  76. fmt->format.code = V4L2_MBUS_FMT_AYUV8_1X32;
  77. format = vsp1_entity_get_pad_format(&rwpf->entity, fh, fmt->pad,
  78. fmt->which);
  79. if (fmt->pad == RWPF_PAD_SOURCE) {
  80. /* The RWPF performs format conversion but can't scale, only the
  81. * format code can be changed on the source pad.
  82. */
  83. format->code = fmt->format.code;
  84. fmt->format = *format;
  85. return 0;
  86. }
  87. format->code = fmt->format.code;
  88. format->width = clamp_t(unsigned int, fmt->format.width,
  89. RWPF_MIN_WIDTH, rwpf->max_width);
  90. format->height = clamp_t(unsigned int, fmt->format.height,
  91. RWPF_MIN_HEIGHT, rwpf->max_height);
  92. format->field = V4L2_FIELD_NONE;
  93. format->colorspace = V4L2_COLORSPACE_SRGB;
  94. fmt->format = *format;
  95. /* Propagate the format to the source pad. */
  96. format = vsp1_entity_get_pad_format(&rwpf->entity, fh, RWPF_PAD_SOURCE,
  97. fmt->which);
  98. *format = fmt->format;
  99. return 0;
  100. }