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>
20 #include "vsp1_hsit.h"
22 #define HSIT_MIN_SIZE 4U
23 #define HSIT_MAX_SIZE 8190U
25 /* -----------------------------------------------------------------------------
29 static inline void vsp1_hsit_write(struct vsp1_hsit *hsit, u32 reg, u32 data)
31 vsp1_write(hsit->entity.vsp1, reg, data);
34 /* -----------------------------------------------------------------------------
35 * V4L2 Subdevice Core Operations
38 static int hsit_s_stream(struct v4l2_subdev *subdev, int enable)
40 struct vsp1_hsit *hsit = to_hsit(subdev);
46 vsp1_hsit_write(hsit, VI6_HSI_CTRL, VI6_HSI_CTRL_EN);
48 vsp1_hsit_write(hsit, VI6_HST_CTRL, VI6_HST_CTRL_EN);
53 /* -----------------------------------------------------------------------------
54 * V4L2 Subdevice Pad Operations
57 static int hsit_enum_mbus_code(struct v4l2_subdev *subdev,
58 struct v4l2_subdev_fh *fh,
59 struct v4l2_subdev_mbus_code_enum *code)
61 struct vsp1_hsit *hsit = to_hsit(subdev);
66 if ((code->pad == HSIT_PAD_SINK && !hsit->inverse) |
67 (code->pad == HSIT_PAD_SOURCE && hsit->inverse))
68 code->code = MEDIA_BUS_FMT_ARGB8888_1X32;
70 code->code = MEDIA_BUS_FMT_AHSV8888_1X32;
75 static int hsit_enum_frame_size(struct v4l2_subdev *subdev,
76 struct v4l2_subdev_fh *fh,
77 struct v4l2_subdev_frame_size_enum *fse)
79 struct v4l2_mbus_framefmt *format;
81 format = v4l2_subdev_get_try_format(fh, fse->pad);
83 if (fse->index || fse->code != format->code)
86 if (fse->pad == HSIT_PAD_SINK) {
87 fse->min_width = HSIT_MIN_SIZE;
88 fse->max_width = HSIT_MAX_SIZE;
89 fse->min_height = HSIT_MIN_SIZE;
90 fse->max_height = HSIT_MAX_SIZE;
92 /* The size on the source pad are fixed and always identical to
93 * the size on the sink pad.
95 fse->min_width = format->width;
96 fse->max_width = format->width;
97 fse->min_height = format->height;
98 fse->max_height = format->height;
104 static int hsit_get_format(struct v4l2_subdev *subdev,
105 struct v4l2_subdev_fh *fh,
106 struct v4l2_subdev_format *fmt)
108 struct vsp1_hsit *hsit = to_hsit(subdev);
110 fmt->format = *vsp1_entity_get_pad_format(&hsit->entity, fh, fmt->pad,
116 static int hsit_set_format(struct v4l2_subdev *subdev,
117 struct v4l2_subdev_fh *fh,
118 struct v4l2_subdev_format *fmt)
120 struct vsp1_hsit *hsit = to_hsit(subdev);
121 struct v4l2_mbus_framefmt *format;
123 format = vsp1_entity_get_pad_format(&hsit->entity, fh, fmt->pad,
126 if (fmt->pad == HSIT_PAD_SOURCE) {
127 /* The HST and HSI output format code and resolution can't be
130 fmt->format = *format;
134 format->code = hsit->inverse ? MEDIA_BUS_FMT_AHSV8888_1X32
135 : MEDIA_BUS_FMT_ARGB8888_1X32;
136 format->width = clamp_t(unsigned int, fmt->format.width,
137 HSIT_MIN_SIZE, HSIT_MAX_SIZE);
138 format->height = clamp_t(unsigned int, fmt->format.height,
139 HSIT_MIN_SIZE, HSIT_MAX_SIZE);
140 format->field = V4L2_FIELD_NONE;
141 format->colorspace = V4L2_COLORSPACE_SRGB;
143 fmt->format = *format;
145 /* Propagate the format to the source pad. */
146 format = vsp1_entity_get_pad_format(&hsit->entity, fh, HSIT_PAD_SOURCE,
148 *format = fmt->format;
149 format->code = hsit->inverse ? MEDIA_BUS_FMT_ARGB8888_1X32
150 : MEDIA_BUS_FMT_AHSV8888_1X32;
155 /* -----------------------------------------------------------------------------
156 * V4L2 Subdevice Operations
159 static struct v4l2_subdev_video_ops hsit_video_ops = {
160 .s_stream = hsit_s_stream,
163 static struct v4l2_subdev_pad_ops hsit_pad_ops = {
164 .enum_mbus_code = hsit_enum_mbus_code,
165 .enum_frame_size = hsit_enum_frame_size,
166 .get_fmt = hsit_get_format,
167 .set_fmt = hsit_set_format,
170 static struct v4l2_subdev_ops hsit_ops = {
171 .video = &hsit_video_ops,
172 .pad = &hsit_pad_ops,
175 /* -----------------------------------------------------------------------------
176 * Initialization and Cleanup
179 struct vsp1_hsit *vsp1_hsit_create(struct vsp1_device *vsp1, bool inverse)
181 struct v4l2_subdev *subdev;
182 struct vsp1_hsit *hsit;
185 hsit = devm_kzalloc(vsp1->dev, sizeof(*hsit), GFP_KERNEL);
187 return ERR_PTR(-ENOMEM);
189 hsit->inverse = inverse;
192 hsit->entity.type = VSP1_ENTITY_HSI;
194 hsit->entity.type = VSP1_ENTITY_HST;
196 ret = vsp1_entity_init(vsp1, &hsit->entity, 2);
200 /* Initialize the V4L2 subdev. */
201 subdev = &hsit->entity.subdev;
202 v4l2_subdev_init(subdev, &hsit_ops);
204 subdev->entity.ops = &vsp1_media_ops;
205 subdev->internal_ops = &vsp1_subdev_internal_ops;
206 snprintf(subdev->name, sizeof(subdev->name), "%s %s",
207 dev_name(vsp1->dev), inverse ? "hsi" : "hst");
208 v4l2_set_subdevdata(subdev, hsit);
209 subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
211 vsp1_entity_init_formats(subdev, NULL);