vsp1_hsit.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * vsp1_hsit.c -- R-Car VSP1 Hue Saturation value (Inverse) Transform
  3. *
  4. * Copyright (C) 2013 Renesas Corporation
  5. *
  6. * Contact: Laurent Pinchart ([email protected])
  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 <linux/gfp.h>
  15. #include <media/v4l2-subdev.h>
  16. #include "vsp1.h"
  17. #include "vsp1_dl.h"
  18. #include "vsp1_hsit.h"
  19. #define HSIT_MIN_SIZE 4U
  20. #define HSIT_MAX_SIZE 8190U
  21. /* -----------------------------------------------------------------------------
  22. * Device Access
  23. */
  24. static inline void vsp1_hsit_write(struct vsp1_hsit *hsit,
  25. struct vsp1_dl_list *dl, u32 reg, u32 data)
  26. {
  27. vsp1_dl_list_write(dl, reg, data);
  28. }
  29. /* -----------------------------------------------------------------------------
  30. * V4L2 Subdevice Operations
  31. */
  32. static int hsit_enum_mbus_code(struct v4l2_subdev *subdev,
  33. struct v4l2_subdev_pad_config *cfg,
  34. struct v4l2_subdev_mbus_code_enum *code)
  35. {
  36. struct vsp1_hsit *hsit = to_hsit(subdev);
  37. if (code->index > 0)
  38. return -EINVAL;
  39. if ((code->pad == HSIT_PAD_SINK && !hsit->inverse) |
  40. (code->pad == HSIT_PAD_SOURCE && hsit->inverse))
  41. code->code = MEDIA_BUS_FMT_ARGB8888_1X32;
  42. else
  43. code->code = MEDIA_BUS_FMT_AHSV8888_1X32;
  44. return 0;
  45. }
  46. static int hsit_enum_frame_size(struct v4l2_subdev *subdev,
  47. struct v4l2_subdev_pad_config *cfg,
  48. struct v4l2_subdev_frame_size_enum *fse)
  49. {
  50. return vsp1_subdev_enum_frame_size(subdev, cfg, fse, HSIT_MIN_SIZE,
  51. HSIT_MIN_SIZE, HSIT_MAX_SIZE,
  52. HSIT_MAX_SIZE);
  53. }
  54. static int hsit_set_format(struct v4l2_subdev *subdev,
  55. struct v4l2_subdev_pad_config *cfg,
  56. struct v4l2_subdev_format *fmt)
  57. {
  58. struct vsp1_hsit *hsit = to_hsit(subdev);
  59. struct v4l2_subdev_pad_config *config;
  60. struct v4l2_mbus_framefmt *format;
  61. int ret = 0;
  62. mutex_lock(&hsit->entity.lock);
  63. config = vsp1_entity_get_pad_config(&hsit->entity, cfg, fmt->which);
  64. if (!config) {
  65. ret = -EINVAL;
  66. goto done;
  67. }
  68. format = vsp1_entity_get_pad_format(&hsit->entity, config, fmt->pad);
  69. if (fmt->pad == HSIT_PAD_SOURCE) {
  70. /* The HST and HSI output format code and resolution can't be
  71. * modified.
  72. */
  73. fmt->format = *format;
  74. goto done;
  75. }
  76. format->code = hsit->inverse ? MEDIA_BUS_FMT_AHSV8888_1X32
  77. : MEDIA_BUS_FMT_ARGB8888_1X32;
  78. format->width = clamp_t(unsigned int, fmt->format.width,
  79. HSIT_MIN_SIZE, HSIT_MAX_SIZE);
  80. format->height = clamp_t(unsigned int, fmt->format.height,
  81. HSIT_MIN_SIZE, HSIT_MAX_SIZE);
  82. format->field = V4L2_FIELD_NONE;
  83. format->colorspace = V4L2_COLORSPACE_SRGB;
  84. fmt->format = *format;
  85. /* Propagate the format to the source pad. */
  86. format = vsp1_entity_get_pad_format(&hsit->entity, config,
  87. HSIT_PAD_SOURCE);
  88. *format = fmt->format;
  89. format->code = hsit->inverse ? MEDIA_BUS_FMT_ARGB8888_1X32
  90. : MEDIA_BUS_FMT_AHSV8888_1X32;
  91. done:
  92. mutex_unlock(&hsit->entity.lock);
  93. return ret;
  94. }
  95. static const struct v4l2_subdev_pad_ops hsit_pad_ops = {
  96. .init_cfg = vsp1_entity_init_cfg,
  97. .enum_mbus_code = hsit_enum_mbus_code,
  98. .enum_frame_size = hsit_enum_frame_size,
  99. .get_fmt = vsp1_subdev_get_pad_format,
  100. .set_fmt = hsit_set_format,
  101. };
  102. static const struct v4l2_subdev_ops hsit_ops = {
  103. .pad = &hsit_pad_ops,
  104. };
  105. /* -----------------------------------------------------------------------------
  106. * VSP1 Entity Operations
  107. */
  108. static void hsit_configure(struct vsp1_entity *entity,
  109. struct vsp1_pipeline *pipe,
  110. struct vsp1_dl_list *dl,
  111. enum vsp1_entity_params params)
  112. {
  113. struct vsp1_hsit *hsit = to_hsit(&entity->subdev);
  114. if (params != VSP1_ENTITY_PARAMS_INIT)
  115. return;
  116. if (hsit->inverse)
  117. vsp1_hsit_write(hsit, dl, VI6_HSI_CTRL, VI6_HSI_CTRL_EN);
  118. else
  119. vsp1_hsit_write(hsit, dl, VI6_HST_CTRL, VI6_HST_CTRL_EN);
  120. }
  121. static const struct vsp1_entity_operations hsit_entity_ops = {
  122. .configure = hsit_configure,
  123. };
  124. /* -----------------------------------------------------------------------------
  125. * Initialization and Cleanup
  126. */
  127. struct vsp1_hsit *vsp1_hsit_create(struct vsp1_device *vsp1, bool inverse)
  128. {
  129. struct vsp1_hsit *hsit;
  130. int ret;
  131. hsit = devm_kzalloc(vsp1->dev, sizeof(*hsit), GFP_KERNEL);
  132. if (hsit == NULL)
  133. return ERR_PTR(-ENOMEM);
  134. hsit->inverse = inverse;
  135. hsit->entity.ops = &hsit_entity_ops;
  136. if (inverse)
  137. hsit->entity.type = VSP1_ENTITY_HSI;
  138. else
  139. hsit->entity.type = VSP1_ENTITY_HST;
  140. ret = vsp1_entity_init(vsp1, &hsit->entity, inverse ? "hsi" : "hst",
  141. 2, &hsit_ops,
  142. MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV);
  143. if (ret < 0)
  144. return ERR_PTR(ret);
  145. return hsit;
  146. }