Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 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 (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 | |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/gfp.h> |
| 16 | |
| 17 | #include <media/v4l2-subdev.h> |
| 18 | |
| 19 | #include "vsp1.h" |
| 20 | #include "vsp1_hsit.h" |
| 21 | |
| 22 | #define HSIT_MIN_SIZE 4U |
| 23 | #define HSIT_MAX_SIZE 8190U |
| 24 | |
| 25 | /* ----------------------------------------------------------------------------- |
| 26 | * Device Access |
| 27 | */ |
| 28 | |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 29 | static inline void vsp1_hsit_write(struct vsp1_hsit *hsit, u32 reg, u32 data) |
| 30 | { |
Laurent Pinchart | 773abaf | 2015-11-01 12:26:14 -0200 | [diff] [blame] | 31 | vsp1_mod_write(&hsit->entity, reg, data); |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame^] | 35 | * V4L2 Subdevice Operations |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 36 | */ |
| 37 | |
| 38 | static int hsit_enum_mbus_code(struct v4l2_subdev *subdev, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 39 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 40 | struct v4l2_subdev_mbus_code_enum *code) |
| 41 | { |
| 42 | struct vsp1_hsit *hsit = to_hsit(subdev); |
| 43 | |
| 44 | if (code->index > 0) |
| 45 | return -EINVAL; |
| 46 | |
| 47 | if ((code->pad == HSIT_PAD_SINK && !hsit->inverse) | |
| 48 | (code->pad == HSIT_PAD_SOURCE && hsit->inverse)) |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 49 | code->code = MEDIA_BUS_FMT_ARGB8888_1X32; |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 50 | else |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 51 | code->code = MEDIA_BUS_FMT_AHSV8888_1X32; |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int hsit_enum_frame_size(struct v4l2_subdev *subdev, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 57 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 58 | struct v4l2_subdev_frame_size_enum *fse) |
| 59 | { |
Hans Verkuil | 5778e74 | 2015-03-04 01:47:58 -0800 | [diff] [blame] | 60 | struct vsp1_hsit *hsit = to_hsit(subdev); |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 61 | struct v4l2_subdev_pad_config *config; |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 62 | struct v4l2_mbus_framefmt *format; |
| 63 | |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 64 | config = vsp1_entity_get_pad_config(&hsit->entity, cfg, fse->which); |
| 65 | if (!config) |
| 66 | return -EINVAL; |
| 67 | |
| 68 | format = vsp1_entity_get_pad_format(&hsit->entity, config, fse->pad); |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 69 | |
| 70 | if (fse->index || fse->code != format->code) |
| 71 | return -EINVAL; |
| 72 | |
| 73 | if (fse->pad == HSIT_PAD_SINK) { |
| 74 | fse->min_width = HSIT_MIN_SIZE; |
| 75 | fse->max_width = HSIT_MAX_SIZE; |
| 76 | fse->min_height = HSIT_MIN_SIZE; |
| 77 | fse->max_height = HSIT_MAX_SIZE; |
| 78 | } else { |
| 79 | /* The size on the source pad are fixed and always identical to |
| 80 | * the size on the sink pad. |
| 81 | */ |
| 82 | fse->min_width = format->width; |
| 83 | fse->max_width = format->width; |
| 84 | fse->min_height = format->height; |
| 85 | fse->max_height = format->height; |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static int hsit_get_format(struct v4l2_subdev *subdev, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 92 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 93 | struct v4l2_subdev_format *fmt) |
| 94 | { |
| 95 | struct vsp1_hsit *hsit = to_hsit(subdev); |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 96 | struct v4l2_subdev_pad_config *config; |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 97 | |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 98 | config = vsp1_entity_get_pad_config(&hsit->entity, cfg, fmt->which); |
| 99 | if (!config) |
| 100 | return -EINVAL; |
| 101 | |
| 102 | fmt->format = *vsp1_entity_get_pad_format(&hsit->entity, config, |
| 103 | fmt->pad); |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int hsit_set_format(struct v4l2_subdev *subdev, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 109 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 110 | struct v4l2_subdev_format *fmt) |
| 111 | { |
| 112 | struct vsp1_hsit *hsit = to_hsit(subdev); |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 113 | struct v4l2_subdev_pad_config *config; |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 114 | struct v4l2_mbus_framefmt *format; |
| 115 | |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 116 | config = vsp1_entity_get_pad_config(&hsit->entity, cfg, fmt->which); |
| 117 | if (!config) |
| 118 | return -EINVAL; |
| 119 | |
| 120 | format = vsp1_entity_get_pad_format(&hsit->entity, config, fmt->pad); |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 121 | |
| 122 | if (fmt->pad == HSIT_PAD_SOURCE) { |
| 123 | /* The HST and HSI output format code and resolution can't be |
| 124 | * modified. |
| 125 | */ |
| 126 | fmt->format = *format; |
| 127 | return 0; |
| 128 | } |
| 129 | |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 130 | format->code = hsit->inverse ? MEDIA_BUS_FMT_AHSV8888_1X32 |
| 131 | : MEDIA_BUS_FMT_ARGB8888_1X32; |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 132 | format->width = clamp_t(unsigned int, fmt->format.width, |
| 133 | HSIT_MIN_SIZE, HSIT_MAX_SIZE); |
| 134 | format->height = clamp_t(unsigned int, fmt->format.height, |
| 135 | HSIT_MIN_SIZE, HSIT_MAX_SIZE); |
| 136 | format->field = V4L2_FIELD_NONE; |
| 137 | format->colorspace = V4L2_COLORSPACE_SRGB; |
| 138 | |
| 139 | fmt->format = *format; |
| 140 | |
| 141 | /* Propagate the format to the source pad. */ |
Laurent Pinchart | e790c3c | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 142 | format = vsp1_entity_get_pad_format(&hsit->entity, config, |
| 143 | HSIT_PAD_SOURCE); |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 144 | *format = fmt->format; |
Boris BREZILLON | 27ffaeb | 2014-11-10 14:28:31 -0300 | [diff] [blame] | 145 | format->code = hsit->inverse ? MEDIA_BUS_FMT_ARGB8888_1X32 |
| 146 | : MEDIA_BUS_FMT_AHSV8888_1X32; |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 151 | static struct v4l2_subdev_pad_ops hsit_pad_ops = { |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 152 | .init_cfg = vsp1_entity_init_cfg, |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 153 | .enum_mbus_code = hsit_enum_mbus_code, |
| 154 | .enum_frame_size = hsit_enum_frame_size, |
| 155 | .get_fmt = hsit_get_format, |
| 156 | .set_fmt = hsit_set_format, |
| 157 | }; |
| 158 | |
| 159 | static struct v4l2_subdev_ops hsit_ops = { |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 160 | .pad = &hsit_pad_ops, |
| 161 | }; |
| 162 | |
| 163 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame^] | 164 | * VSP1 Entity Operations |
| 165 | */ |
| 166 | |
| 167 | static void hsit_configure(struct vsp1_entity *entity) |
| 168 | { |
| 169 | struct vsp1_hsit *hsit = to_hsit(&entity->subdev); |
| 170 | |
| 171 | if (hsit->inverse) |
| 172 | vsp1_hsit_write(hsit, VI6_HSI_CTRL, VI6_HSI_CTRL_EN); |
| 173 | else |
| 174 | vsp1_hsit_write(hsit, VI6_HST_CTRL, VI6_HST_CTRL_EN); |
| 175 | } |
| 176 | |
| 177 | static const struct vsp1_entity_operations hsit_entity_ops = { |
| 178 | .configure = hsit_configure, |
| 179 | }; |
| 180 | |
| 181 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 182 | * Initialization and Cleanup |
| 183 | */ |
| 184 | |
| 185 | struct vsp1_hsit *vsp1_hsit_create(struct vsp1_device *vsp1, bool inverse) |
| 186 | { |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 187 | struct vsp1_hsit *hsit; |
| 188 | int ret; |
| 189 | |
| 190 | hsit = devm_kzalloc(vsp1->dev, sizeof(*hsit), GFP_KERNEL); |
| 191 | if (hsit == NULL) |
| 192 | return ERR_PTR(-ENOMEM); |
| 193 | |
| 194 | hsit->inverse = inverse; |
| 195 | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame^] | 196 | hsit->entity.ops = &hsit_entity_ops; |
| 197 | |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 198 | if (inverse) |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 199 | hsit->entity.type = VSP1_ENTITY_HSI; |
Laurent Pinchart | d9b45ed | 2013-07-10 18:37:27 -0300 | [diff] [blame] | 200 | else |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 201 | hsit->entity.type = VSP1_ENTITY_HST; |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 202 | |
Laurent Pinchart | 823329d | 2015-11-15 19:42:01 -0200 | [diff] [blame] | 203 | ret = vsp1_entity_init(vsp1, &hsit->entity, inverse ? "hsi" : "hst", 2, |
| 204 | &hsit_ops); |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 205 | if (ret < 0) |
| 206 | return ERR_PTR(ret); |
| 207 | |
Laurent Pinchart | 5cdf574 | 2013-07-10 17:30:14 -0300 | [diff] [blame] | 208 | return hsit; |
| 209 | } |