]>
Commit | Line | Data |
---|---|---|
5cdf5741 LP |
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" | |
5e8dbbf3 | 20 | #include "vsp1_dl.h" |
5cdf5741 LP |
21 | #include "vsp1_hsit.h" |
22 | ||
23 | #define HSIT_MIN_SIZE 4U | |
24 | #define HSIT_MAX_SIZE 8190U | |
25 | ||
26 | /* ----------------------------------------------------------------------------- | |
27 | * Device Access | |
28 | */ | |
29 | ||
5e8dbbf3 LP |
30 | static inline void vsp1_hsit_write(struct vsp1_hsit *hsit, |
31 | struct vsp1_dl_list *dl, u32 reg, u32 data) | |
5cdf5741 | 32 | { |
5e8dbbf3 | 33 | vsp1_dl_list_write(dl, reg, data); |
5cdf5741 LP |
34 | } |
35 | ||
36 | /* ----------------------------------------------------------------------------- | |
7b905f05 | 37 | * V4L2 Subdevice Operations |
5cdf5741 LP |
38 | */ |
39 | ||
40 | static int hsit_enum_mbus_code(struct v4l2_subdev *subdev, | |
f7234138 | 41 | struct v4l2_subdev_pad_config *cfg, |
5cdf5741 LP |
42 | struct v4l2_subdev_mbus_code_enum *code) |
43 | { | |
44 | struct vsp1_hsit *hsit = to_hsit(subdev); | |
45 | ||
46 | if (code->index > 0) | |
47 | return -EINVAL; | |
48 | ||
49 | if ((code->pad == HSIT_PAD_SINK && !hsit->inverse) | | |
50 | (code->pad == HSIT_PAD_SOURCE && hsit->inverse)) | |
27ffaeb0 | 51 | code->code = MEDIA_BUS_FMT_ARGB8888_1X32; |
5cdf5741 | 52 | else |
27ffaeb0 | 53 | code->code = MEDIA_BUS_FMT_AHSV8888_1X32; |
5cdf5741 LP |
54 | |
55 | return 0; | |
56 | } | |
57 | ||
58 | static int hsit_enum_frame_size(struct v4l2_subdev *subdev, | |
f7234138 | 59 | struct v4l2_subdev_pad_config *cfg, |
5cdf5741 LP |
60 | struct v4l2_subdev_frame_size_enum *fse) |
61 | { | |
076e834f LP |
62 | return vsp1_subdev_enum_frame_size(subdev, cfg, fse, HSIT_MIN_SIZE, |
63 | HSIT_MIN_SIZE, HSIT_MAX_SIZE, | |
64 | HSIT_MAX_SIZE); | |
5cdf5741 LP |
65 | } |
66 | ||
5cdf5741 | 67 | static int hsit_set_format(struct v4l2_subdev *subdev, |
f7234138 | 68 | struct v4l2_subdev_pad_config *cfg, |
5cdf5741 LP |
69 | struct v4l2_subdev_format *fmt) |
70 | { | |
71 | struct vsp1_hsit *hsit = to_hsit(subdev); | |
e790c3cb | 72 | struct v4l2_subdev_pad_config *config; |
5cdf5741 LP |
73 | struct v4l2_mbus_framefmt *format; |
74 | ||
e790c3cb LP |
75 | config = vsp1_entity_get_pad_config(&hsit->entity, cfg, fmt->which); |
76 | if (!config) | |
77 | return -EINVAL; | |
78 | ||
79 | format = vsp1_entity_get_pad_format(&hsit->entity, config, fmt->pad); | |
5cdf5741 LP |
80 | |
81 | if (fmt->pad == HSIT_PAD_SOURCE) { | |
82 | /* The HST and HSI output format code and resolution can't be | |
83 | * modified. | |
84 | */ | |
85 | fmt->format = *format; | |
86 | return 0; | |
87 | } | |
88 | ||
27ffaeb0 BB |
89 | format->code = hsit->inverse ? MEDIA_BUS_FMT_AHSV8888_1X32 |
90 | : MEDIA_BUS_FMT_ARGB8888_1X32; | |
5cdf5741 LP |
91 | format->width = clamp_t(unsigned int, fmt->format.width, |
92 | HSIT_MIN_SIZE, HSIT_MAX_SIZE); | |
93 | format->height = clamp_t(unsigned int, fmt->format.height, | |
94 | HSIT_MIN_SIZE, HSIT_MAX_SIZE); | |
95 | format->field = V4L2_FIELD_NONE; | |
96 | format->colorspace = V4L2_COLORSPACE_SRGB; | |
97 | ||
98 | fmt->format = *format; | |
99 | ||
100 | /* Propagate the format to the source pad. */ | |
e790c3cb LP |
101 | format = vsp1_entity_get_pad_format(&hsit->entity, config, |
102 | HSIT_PAD_SOURCE); | |
5cdf5741 | 103 | *format = fmt->format; |
27ffaeb0 BB |
104 | format->code = hsit->inverse ? MEDIA_BUS_FMT_ARGB8888_1X32 |
105 | : MEDIA_BUS_FMT_AHSV8888_1X32; | |
5cdf5741 LP |
106 | |
107 | return 0; | |
108 | } | |
109 | ||
5cdf5741 | 110 | static struct v4l2_subdev_pad_ops hsit_pad_ops = { |
0efdf0f5 | 111 | .init_cfg = vsp1_entity_init_cfg, |
5cdf5741 LP |
112 | .enum_mbus_code = hsit_enum_mbus_code, |
113 | .enum_frame_size = hsit_enum_frame_size, | |
3f557220 | 114 | .get_fmt = vsp1_subdev_get_pad_format, |
5cdf5741 LP |
115 | .set_fmt = hsit_set_format, |
116 | }; | |
117 | ||
118 | static struct v4l2_subdev_ops hsit_ops = { | |
5cdf5741 LP |
119 | .pad = &hsit_pad_ops, |
120 | }; | |
121 | ||
7b905f05 LP |
122 | /* ----------------------------------------------------------------------------- |
123 | * VSP1 Entity Operations | |
124 | */ | |
125 | ||
83dd019d LP |
126 | static void hsit_configure(struct vsp1_entity *entity, |
127 | struct vsp1_pipeline *pipe, | |
128 | struct vsp1_dl_list *dl) | |
7b905f05 LP |
129 | { |
130 | struct vsp1_hsit *hsit = to_hsit(&entity->subdev); | |
131 | ||
132 | if (hsit->inverse) | |
5e8dbbf3 | 133 | vsp1_hsit_write(hsit, dl, VI6_HSI_CTRL, VI6_HSI_CTRL_EN); |
7b905f05 | 134 | else |
5e8dbbf3 | 135 | vsp1_hsit_write(hsit, dl, VI6_HST_CTRL, VI6_HST_CTRL_EN); |
7b905f05 LP |
136 | } |
137 | ||
138 | static const struct vsp1_entity_operations hsit_entity_ops = { | |
139 | .configure = hsit_configure, | |
140 | }; | |
141 | ||
5cdf5741 LP |
142 | /* ----------------------------------------------------------------------------- |
143 | * Initialization and Cleanup | |
144 | */ | |
145 | ||
146 | struct vsp1_hsit *vsp1_hsit_create(struct vsp1_device *vsp1, bool inverse) | |
147 | { | |
5cdf5741 LP |
148 | struct vsp1_hsit *hsit; |
149 | int ret; | |
150 | ||
151 | hsit = devm_kzalloc(vsp1->dev, sizeof(*hsit), GFP_KERNEL); | |
152 | if (hsit == NULL) | |
153 | return ERR_PTR(-ENOMEM); | |
154 | ||
155 | hsit->inverse = inverse; | |
156 | ||
7b905f05 LP |
157 | hsit->entity.ops = &hsit_entity_ops; |
158 | ||
d9b45ed3 | 159 | if (inverse) |
5cdf5741 | 160 | hsit->entity.type = VSP1_ENTITY_HSI; |
d9b45ed3 | 161 | else |
5cdf5741 | 162 | hsit->entity.type = VSP1_ENTITY_HST; |
5cdf5741 | 163 | |
823329df LP |
164 | ret = vsp1_entity_init(vsp1, &hsit->entity, inverse ? "hsi" : "hst", 2, |
165 | &hsit_ops); | |
5cdf5741 LP |
166 | if (ret < 0) |
167 | return ERR_PTR(ret); | |
168 | ||
5cdf5741 LP |
169 | return hsit; |
170 | } |