Linux 4.14.51
[linux/fpc-iii.git] / drivers / media / platform / vsp1 / vsp1_hsit.c
blob764d405345eedfea4f6146bb29d3a18a9cf0d6c5
1 /*
2 * vsp1_hsit.c -- R-Car VSP1 Hue Saturation value (Inverse) Transform
4 * Copyright (C) 2013 Renesas Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
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.
14 #include <linux/device.h>
15 #include <linux/gfp.h>
17 #include <media/v4l2-subdev.h>
19 #include "vsp1.h"
20 #include "vsp1_dl.h"
21 #include "vsp1_hsit.h"
23 #define HSIT_MIN_SIZE 4U
24 #define HSIT_MAX_SIZE 8190U
26 /* -----------------------------------------------------------------------------
27 * Device Access
30 static inline void vsp1_hsit_write(struct vsp1_hsit *hsit,
31 struct vsp1_dl_list *dl, u32 reg, u32 data)
33 vsp1_dl_list_write(dl, reg, data);
36 /* -----------------------------------------------------------------------------
37 * V4L2 Subdevice Operations
40 static int hsit_enum_mbus_code(struct v4l2_subdev *subdev,
41 struct v4l2_subdev_pad_config *cfg,
42 struct v4l2_subdev_mbus_code_enum *code)
44 struct vsp1_hsit *hsit = to_hsit(subdev);
46 if (code->index > 0)
47 return -EINVAL;
49 if ((code->pad == HSIT_PAD_SINK && !hsit->inverse) |
50 (code->pad == HSIT_PAD_SOURCE && hsit->inverse))
51 code->code = MEDIA_BUS_FMT_ARGB8888_1X32;
52 else
53 code->code = MEDIA_BUS_FMT_AHSV8888_1X32;
55 return 0;
58 static int hsit_enum_frame_size(struct v4l2_subdev *subdev,
59 struct v4l2_subdev_pad_config *cfg,
60 struct v4l2_subdev_frame_size_enum *fse)
62 return vsp1_subdev_enum_frame_size(subdev, cfg, fse, HSIT_MIN_SIZE,
63 HSIT_MIN_SIZE, HSIT_MAX_SIZE,
64 HSIT_MAX_SIZE);
67 static int hsit_set_format(struct v4l2_subdev *subdev,
68 struct v4l2_subdev_pad_config *cfg,
69 struct v4l2_subdev_format *fmt)
71 struct vsp1_hsit *hsit = to_hsit(subdev);
72 struct v4l2_subdev_pad_config *config;
73 struct v4l2_mbus_framefmt *format;
74 int ret = 0;
76 mutex_lock(&hsit->entity.lock);
78 config = vsp1_entity_get_pad_config(&hsit->entity, cfg, fmt->which);
79 if (!config) {
80 ret = -EINVAL;
81 goto done;
84 format = vsp1_entity_get_pad_format(&hsit->entity, config, fmt->pad);
86 if (fmt->pad == HSIT_PAD_SOURCE) {
88 * The HST and HSI output format code and resolution can't be
89 * modified.
91 fmt->format = *format;
92 goto done;
95 format->code = hsit->inverse ? MEDIA_BUS_FMT_AHSV8888_1X32
96 : MEDIA_BUS_FMT_ARGB8888_1X32;
97 format->width = clamp_t(unsigned int, fmt->format.width,
98 HSIT_MIN_SIZE, HSIT_MAX_SIZE);
99 format->height = clamp_t(unsigned int, fmt->format.height,
100 HSIT_MIN_SIZE, HSIT_MAX_SIZE);
101 format->field = V4L2_FIELD_NONE;
102 format->colorspace = V4L2_COLORSPACE_SRGB;
104 fmt->format = *format;
106 /* Propagate the format to the source pad. */
107 format = vsp1_entity_get_pad_format(&hsit->entity, config,
108 HSIT_PAD_SOURCE);
109 *format = fmt->format;
110 format->code = hsit->inverse ? MEDIA_BUS_FMT_ARGB8888_1X32
111 : MEDIA_BUS_FMT_AHSV8888_1X32;
113 done:
114 mutex_unlock(&hsit->entity.lock);
115 return ret;
118 static const struct v4l2_subdev_pad_ops hsit_pad_ops = {
119 .init_cfg = vsp1_entity_init_cfg,
120 .enum_mbus_code = hsit_enum_mbus_code,
121 .enum_frame_size = hsit_enum_frame_size,
122 .get_fmt = vsp1_subdev_get_pad_format,
123 .set_fmt = hsit_set_format,
126 static const struct v4l2_subdev_ops hsit_ops = {
127 .pad = &hsit_pad_ops,
130 /* -----------------------------------------------------------------------------
131 * VSP1 Entity Operations
134 static void hsit_configure(struct vsp1_entity *entity,
135 struct vsp1_pipeline *pipe,
136 struct vsp1_dl_list *dl,
137 enum vsp1_entity_params params)
139 struct vsp1_hsit *hsit = to_hsit(&entity->subdev);
141 if (params != VSP1_ENTITY_PARAMS_INIT)
142 return;
144 if (hsit->inverse)
145 vsp1_hsit_write(hsit, dl, VI6_HSI_CTRL, VI6_HSI_CTRL_EN);
146 else
147 vsp1_hsit_write(hsit, dl, VI6_HST_CTRL, VI6_HST_CTRL_EN);
150 static const struct vsp1_entity_operations hsit_entity_ops = {
151 .configure = hsit_configure,
154 /* -----------------------------------------------------------------------------
155 * Initialization and Cleanup
158 struct vsp1_hsit *vsp1_hsit_create(struct vsp1_device *vsp1, bool inverse)
160 struct vsp1_hsit *hsit;
161 int ret;
163 hsit = devm_kzalloc(vsp1->dev, sizeof(*hsit), GFP_KERNEL);
164 if (hsit == NULL)
165 return ERR_PTR(-ENOMEM);
167 hsit->inverse = inverse;
169 hsit->entity.ops = &hsit_entity_ops;
171 if (inverse)
172 hsit->entity.type = VSP1_ENTITY_HSI;
173 else
174 hsit->entity.type = VSP1_ENTITY_HST;
176 ret = vsp1_entity_init(vsp1, &hsit->entity, inverse ? "hsi" : "hst",
177 2, &hsit_ops,
178 MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV);
179 if (ret < 0)
180 return ERR_PTR(ret);
182 return hsit;