Lines Matching +full:solid +full:- +full:state
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2013-2015 Ideas on Board
6 * Copyright (C) 2013-2015 Xilinx, Inc.
17 #include <linux/xilinx-v4l2-controls.h>
19 #include <media/v4l2-async.h>
20 #include <media/v4l2-ctrls.h>
21 #include <media/v4l2-subdev.h>
23 #include "xilinx-vip.h"
24 #include "xilinx-vtc.h"
66 #define XTPG_MAX_HBLANK (XVTC_MAX_HSIZE - XVIP_MIN_WIDTH)
68 #define XTPG_MAX_VBLANK (XVTC_MAX_VSIZE - XVIP_MIN_HEIGHT)
71 * struct xtpg_device - Xilinx Test Pattern Generator device structure
134 u32 pattern_mask = (1 << (xtpg->pattern->maximum + 1)) - 1; in __xtpg_update_pattern_control()
140 if (xtpg->npads == 1 || !xtpg->has_input) in __xtpg_update_pattern_control()
151 __v4l2_ctrl_modify_range(xtpg->pattern, 0, xtpg->pattern->maximum, in __xtpg_update_pattern_control()
158 mutex_lock(xtpg->ctrl_handler.lock); in xtpg_update_pattern_control()
160 mutex_unlock(xtpg->ctrl_handler.lock); in xtpg_update_pattern_control()
163 /* -----------------------------------------------------------------------------
170 unsigned int width = xtpg->formats[0].width; in xtpg_s_stream()
171 unsigned int height = xtpg->formats[0].height; in xtpg_s_stream()
176 xvip_stop(&xtpg->xvip); in xtpg_s_stream()
177 if (xtpg->vtc) in xtpg_s_stream()
178 xvtc_generator_stop(xtpg->vtc); in xtpg_s_stream()
181 xtpg->streaming = false; in xtpg_s_stream()
185 xvip_set_frame_size(&xtpg->xvip, &xtpg->formats[0]); in xtpg_s_stream()
187 if (xtpg->vtc) { in xtpg_s_stream()
198 v4l2_ctrl_g_ctrl(xtpg->hblank) + width); in xtpg_s_stream()
200 v4l2_ctrl_g_ctrl(xtpg->vblank) + height); in xtpg_s_stream()
202 config.hsync_end = htotal - 1; in xtpg_s_stream()
204 config.vsync_end = vtotal - 1; in xtpg_s_stream()
207 xvtc_generator_start(xtpg->vtc, &config); in xtpg_s_stream()
216 mutex_lock(xtpg->ctrl_handler.lock); in xtpg_s_stream()
218 xvip_clr_and_set(&xtpg->xvip, XTPG_PATTERN_CONTROL, in xtpg_s_stream()
219 XTPG_PATTERN_MASK, xtpg->pattern->cur.val); in xtpg_s_stream()
225 passthrough = xtpg->pattern->cur.val == 0; in xtpg_s_stream()
228 xtpg->streaming = true; in xtpg_s_stream()
230 mutex_unlock(xtpg->ctrl_handler.lock); in xtpg_s_stream()
237 : xtpg_get_bayer_phase(xtpg->formats[0].code); in xtpg_s_stream()
238 xvip_write(&xtpg->xvip, XTPG_BAYER_PHASE, bayer_phase); in xtpg_s_stream()
240 if (xtpg->vtmux_gpio) in xtpg_s_stream()
241 gpiod_set_value_cansleep(xtpg->vtmux_gpio, !passthrough); in xtpg_s_stream()
243 xvip_start(&xtpg->xvip); in xtpg_s_stream()
248 /* -----------------------------------------------------------------------------
261 return &xtpg->formats[pad]; in __xtpg_get_pad_format()
273 fmt->format = *__xtpg_get_pad_format(xtpg, sd_state, fmt->pad, in xtpg_get_format()
274 fmt->which); in xtpg_get_format()
287 __format = __xtpg_get_pad_format(xtpg, sd_state, fmt->pad, fmt->which); in xtpg_set_format()
292 if (xtpg->npads == 2 && fmt->pad == 1) { in xtpg_set_format()
293 fmt->format = *__format; in xtpg_set_format()
298 if (xtpg->bayer) { in xtpg_set_format()
299 bayer_phase = xtpg_get_bayer_phase(fmt->format.code); in xtpg_set_format()
301 __format->code = fmt->format.code; in xtpg_set_format()
306 fmt->format = *__format; in xtpg_set_format()
309 if (xtpg->npads == 2) { in xtpg_set_format()
311 fmt->which); in xtpg_set_format()
312 *__format = fmt->format; in xtpg_set_format()
318 /* -----------------------------------------------------------------------------
328 format = v4l2_subdev_state_get_format(sd_state, fse->pad); in xtpg_enum_frame_size()
330 if (fse->index || fse->code != format->code) in xtpg_enum_frame_size()
331 return -EINVAL; in xtpg_enum_frame_size()
336 if (fse->pad == 0) { in xtpg_enum_frame_size()
337 fse->min_width = XVIP_MIN_WIDTH; in xtpg_enum_frame_size()
338 fse->max_width = XVIP_MAX_WIDTH; in xtpg_enum_frame_size()
339 fse->min_height = XVIP_MIN_HEIGHT; in xtpg_enum_frame_size()
340 fse->max_height = XVIP_MAX_HEIGHT; in xtpg_enum_frame_size()
342 fse->min_width = format->width; in xtpg_enum_frame_size()
343 fse->max_width = format->width; in xtpg_enum_frame_size()
344 fse->min_height = format->height; in xtpg_enum_frame_size()
345 fse->max_height = format->height; in xtpg_enum_frame_size()
356 format = v4l2_subdev_state_get_format(fh->state, 0); in xtpg_open()
357 *format = xtpg->default_format; in xtpg_open()
359 if (xtpg->npads == 2) { in xtpg_open()
360 format = v4l2_subdev_state_get_format(fh->state, 1); in xtpg_open()
361 *format = xtpg->default_format; in xtpg_open()
374 struct xtpg_device *xtpg = container_of(ctrl->handler, in xtpg_s_ctrl()
377 switch (ctrl->id) { in xtpg_s_ctrl()
379 xvip_clr_and_set(&xtpg->xvip, XTPG_PATTERN_CONTROL, in xtpg_s_ctrl()
380 XTPG_PATTERN_MASK, ctrl->val); in xtpg_s_ctrl()
383 xvip_clr_or_set(&xtpg->xvip, XTPG_PATTERN_CONTROL, in xtpg_s_ctrl()
384 XTPG_PATTERN_CONTROL_CROSS_HAIRS, ctrl->val); in xtpg_s_ctrl()
387 xvip_clr_or_set(&xtpg->xvip, XTPG_PATTERN_CONTROL, in xtpg_s_ctrl()
388 XTPG_PATTERN_CONTROL_MOVING_BOX, ctrl->val); in xtpg_s_ctrl()
391 xvip_clr_and_set(&xtpg->xvip, XTPG_PATTERN_CONTROL, in xtpg_s_ctrl()
393 ctrl->val << in xtpg_s_ctrl()
397 xvip_clr_or_set(&xtpg->xvip, XTPG_PATTERN_CONTROL, in xtpg_s_ctrl()
398 XTPG_PATTERN_CONTROL_STUCK_PIXEL, ctrl->val); in xtpg_s_ctrl()
401 xvip_clr_or_set(&xtpg->xvip, XTPG_PATTERN_CONTROL, in xtpg_s_ctrl()
402 XTPG_PATTERN_CONTROL_NOISE, ctrl->val); in xtpg_s_ctrl()
405 xvip_clr_or_set(&xtpg->xvip, XTPG_PATTERN_CONTROL, in xtpg_s_ctrl()
406 XTPG_PATTERN_CONTROL_MOTION, ctrl->val); in xtpg_s_ctrl()
409 xvip_write(&xtpg->xvip, XTPG_MOTION_SPEED, ctrl->val); in xtpg_s_ctrl()
412 xvip_clr_and_set(&xtpg->xvip, XTPG_CROSS_HAIRS, in xtpg_s_ctrl()
414 ctrl->val << XTPG_CROSS_HAIRS_ROW_SHIFT); in xtpg_s_ctrl()
417 xvip_clr_and_set(&xtpg->xvip, XTPG_CROSS_HAIRS, in xtpg_s_ctrl()
419 ctrl->val << XTPG_CROSS_HAIRS_COLUMN_SHIFT); in xtpg_s_ctrl()
422 xvip_clr_and_set(&xtpg->xvip, XTPG_ZPLATE_HOR_CONTROL, in xtpg_s_ctrl()
424 ctrl->val << XTPG_ZPLATE_START_SHIFT); in xtpg_s_ctrl()
427 xvip_clr_and_set(&xtpg->xvip, XTPG_ZPLATE_HOR_CONTROL, in xtpg_s_ctrl()
429 ctrl->val << XTPG_ZPLATE_SPEED_SHIFT); in xtpg_s_ctrl()
432 xvip_clr_and_set(&xtpg->xvip, XTPG_ZPLATE_VER_CONTROL, in xtpg_s_ctrl()
434 ctrl->val << XTPG_ZPLATE_START_SHIFT); in xtpg_s_ctrl()
437 xvip_clr_and_set(&xtpg->xvip, XTPG_ZPLATE_VER_CONTROL, in xtpg_s_ctrl()
439 ctrl->val << XTPG_ZPLATE_SPEED_SHIFT); in xtpg_s_ctrl()
442 xvip_write(&xtpg->xvip, XTPG_BOX_SIZE, ctrl->val); in xtpg_s_ctrl()
445 xvip_write(&xtpg->xvip, XTPG_BOX_COLOR, ctrl->val); in xtpg_s_ctrl()
448 xvip_write(&xtpg->xvip, XTPG_STUCK_PIXEL_THRESH, ctrl->val); in xtpg_s_ctrl()
451 xvip_write(&xtpg->xvip, XTPG_NOISE_GAIN, ctrl->val); in xtpg_s_ctrl()
496 "Solid Red",
497 "Solid Green",
498 "Solid Blue",
499 "Solid Black",
500 "Solid White",
570 .max = (1 << 8) - 1,
580 .max = (1 << 12) - 1,
590 .max = (1 << 12) - 1,
600 .max = (1 << 16) - 1,
610 .max = (1 << 16) - 1,
620 .max = (1 << 16) - 1,
630 .max = (1 << 16) - 1,
640 .max = (1 << 12) - 1,
650 .max = (1 << 24) - 1,
659 .max = (1 << 16) - 1,
669 .max = (1 << 8) - 1,
676 /* -----------------------------------------------------------------------------
684 /* -----------------------------------------------------------------------------
692 xvip_suspend(&xtpg->xvip); in xtpg_pm_suspend()
701 xvip_resume(&xtpg->xvip); in xtpg_pm_resume()
706 /* -----------------------------------------------------------------------------
712 struct device *dev = xtpg->xvip.dev; in xtpg_parse_of()
713 struct device_node *node = xtpg->xvip.dev->of_node; in xtpg_parse_of()
738 if (!xtpg->vip_format) { in xtpg_parse_of()
739 xtpg->vip_format = format; in xtpg_parse_of()
740 } else if (xtpg->vip_format != format) { in xtpg_parse_of()
743 return -EINVAL; in xtpg_parse_of()
759 return -EINVAL; in xtpg_parse_of()
762 xtpg->npads = nports; in xtpg_parse_of()
764 xtpg->has_input = true; in xtpg_parse_of()
776 xtpg = devm_kzalloc(&pdev->dev, sizeof(*xtpg), GFP_KERNEL); in xtpg_probe()
778 return -ENOMEM; in xtpg_probe()
780 xtpg->xvip.dev = &pdev->dev; in xtpg_probe()
786 ret = xvip_init_resources(&xtpg->xvip); in xtpg_probe()
790 xtpg->vtmux_gpio = devm_gpiod_get_optional(&pdev->dev, "timing", in xtpg_probe()
792 if (IS_ERR(xtpg->vtmux_gpio)) { in xtpg_probe()
793 ret = PTR_ERR(xtpg->vtmux_gpio); in xtpg_probe()
797 xtpg->vtc = xvtc_of_get(pdev->dev.of_node); in xtpg_probe()
798 if (IS_ERR(xtpg->vtc)) { in xtpg_probe()
799 ret = PTR_ERR(xtpg->vtc); in xtpg_probe()
804 xvip_reset(&xtpg->xvip); in xtpg_probe()
809 if (xtpg->npads == 2) { in xtpg_probe()
810 xtpg->pads[0].flags = MEDIA_PAD_FL_SINK; in xtpg_probe()
811 xtpg->pads[1].flags = MEDIA_PAD_FL_SOURCE; in xtpg_probe()
813 xtpg->pads[0].flags = MEDIA_PAD_FL_SOURCE; in xtpg_probe()
817 xtpg->default_format.code = xtpg->vip_format->code; in xtpg_probe()
818 xtpg->default_format.field = V4L2_FIELD_NONE; in xtpg_probe()
819 xtpg->default_format.colorspace = V4L2_COLORSPACE_SRGB; in xtpg_probe()
820 xvip_get_frame_size(&xtpg->xvip, &xtpg->default_format); in xtpg_probe()
822 bayer_phase = xtpg_get_bayer_phase(xtpg->vip_format->code); in xtpg_probe()
824 xtpg->bayer = true; in xtpg_probe()
826 xtpg->formats[0] = xtpg->default_format; in xtpg_probe()
827 if (xtpg->npads == 2) in xtpg_probe()
828 xtpg->formats[1] = xtpg->default_format; in xtpg_probe()
831 subdev = &xtpg->xvip.subdev; in xtpg_probe()
833 subdev->dev = &pdev->dev; in xtpg_probe()
834 subdev->internal_ops = &xtpg_internal_ops; in xtpg_probe()
835 strscpy(subdev->name, dev_name(&pdev->dev), sizeof(subdev->name)); in xtpg_probe()
837 subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in xtpg_probe()
838 subdev->entity.ops = &xtpg_media_ops; in xtpg_probe()
840 ret = media_entity_pads_init(&subdev->entity, xtpg->npads, xtpg->pads); in xtpg_probe()
844 v4l2_ctrl_handler_init(&xtpg->ctrl_handler, 3 + ARRAY_SIZE(xtpg_ctrls)); in xtpg_probe()
846 xtpg->vblank = v4l2_ctrl_new_std(&xtpg->ctrl_handler, &xtpg_ctrl_ops, in xtpg_probe()
849 xtpg->hblank = v4l2_ctrl_new_std(&xtpg->ctrl_handler, &xtpg_ctrl_ops, in xtpg_probe()
852 xtpg->pattern = v4l2_ctrl_new_std_menu_items(&xtpg->ctrl_handler, in xtpg_probe()
854 ARRAY_SIZE(xtpg_pattern_strings) - 1, in xtpg_probe()
858 v4l2_ctrl_new_custom(&xtpg->ctrl_handler, &xtpg_ctrls[i], NULL); in xtpg_probe()
860 if (xtpg->ctrl_handler.error) { in xtpg_probe()
861 dev_err(&pdev->dev, "failed to add controls\n"); in xtpg_probe()
862 ret = xtpg->ctrl_handler.error; in xtpg_probe()
865 subdev->ctrl_handler = &xtpg->ctrl_handler; in xtpg_probe()
869 ret = v4l2_ctrl_handler_setup(&xtpg->ctrl_handler); in xtpg_probe()
871 dev_err(&pdev->dev, "failed to set controls\n"); in xtpg_probe()
877 xvip_print_version(&xtpg->xvip); in xtpg_probe()
881 dev_err(&pdev->dev, "failed to register subdev\n"); in xtpg_probe()
888 v4l2_ctrl_handler_free(&xtpg->ctrl_handler); in xtpg_probe()
889 media_entity_cleanup(&subdev->entity); in xtpg_probe()
890 xvtc_put(xtpg->vtc); in xtpg_probe()
892 xvip_cleanup_resources(&xtpg->xvip); in xtpg_probe()
899 struct v4l2_subdev *subdev = &xtpg->xvip.subdev; in xtpg_remove()
902 v4l2_ctrl_handler_free(&xtpg->ctrl_handler); in xtpg_remove()
903 media_entity_cleanup(&subdev->entity); in xtpg_remove()
905 xvip_cleanup_resources(&xtpg->xvip); in xtpg_remove()
911 { .compatible = "xlnx,v-tpg-5.0" },
918 .name = "xilinx-tpg",