Lines Matching +full:top +full:- +full:ctrl
1 // SPDX-License-Identifier: GPL-2.0-only
15 * Copyright 2006-7 Jonathan Corbet <corbet@lwn.net>
28 #include <linux/v4l2-mediabus.h>
31 #include <media/v4l2-clk.h>
32 #include <media/v4l2-ctrls.h>
33 #include <media/v4l2-device.h>
36 #define REG_GAIN 0x00 /* range 00 - 3F */
51 /* [5:0]: Internal Clock Pre-Scaler */
165 #define W_QCIF (DEF_HSTOP - DEF_HSTRT)
167 #define H_QCIF (DEF_VSTOP - DEF_VSTRT)
254 .addr = client->addr, in ov6650_reg_read()
260 ret = i2c_transfer(client->adapter, &msg, 1); in ov6650_reg_read()
265 ret = i2c_transfer(client->adapter, &msg, 1); in ov6650_reg_read()
273 dev_err(&client->dev, "Failed reading register 0x%02x!\n", reg); in ov6650_reg_read()
283 .addr = client->addr, in ov6650_reg_write()
289 ret = i2c_transfer(client->adapter, &msg, 1); in ov6650_reg_write()
293 dev_err(&client->dev, "Failed writing register 0x%02x!\n", reg); in ov6650_reg_write()
308 dev_err(&client->dev, in ov6650_reg_rmw()
309 "[Read]-Modify-Write of register 0x%02x failed!\n", in ov6650_reg_rmw()
319 dev_err(&client->dev, in ov6650_reg_rmw()
320 "Read-Modify-[Write] of register 0x%02x failed!\n", in ov6650_reg_rmw()
338 static int ov6550_g_volatile_ctrl(struct v4l2_ctrl *ctrl) in ov6550_g_volatile_ctrl() argument
340 struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl); in ov6550_g_volatile_ctrl()
341 struct v4l2_subdev *sd = &priv->subdev; in ov6550_g_volatile_ctrl()
346 switch (ctrl->id) { in ov6550_g_volatile_ctrl()
350 priv->gain->val = reg; in ov6550_g_volatile_ctrl()
357 priv->blue->val = reg; in ov6550_g_volatile_ctrl()
358 priv->red->val = reg2; in ov6550_g_volatile_ctrl()
364 priv->exposure->val = reg; in ov6550_g_volatile_ctrl()
367 return -EINVAL; in ov6550_g_volatile_ctrl()
371 static int ov6550_s_ctrl(struct v4l2_ctrl *ctrl) in ov6550_s_ctrl() argument
373 struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl); in ov6550_s_ctrl()
374 struct v4l2_subdev *sd = &priv->subdev; in ov6550_s_ctrl()
378 switch (ctrl->id) { in ov6550_s_ctrl()
381 ctrl->val ? COMB_AGC : 0, COMB_AGC); in ov6550_s_ctrl()
382 if (!ret && !ctrl->val) in ov6550_s_ctrl()
383 ret = ov6650_reg_write(client, REG_GAIN, priv->gain->val); in ov6550_s_ctrl()
387 ctrl->val ? COMB_AWB : 0, COMB_AWB); in ov6550_s_ctrl()
388 if (!ret && !ctrl->val) { in ov6550_s_ctrl()
389 ret = ov6650_reg_write(client, REG_BLUE, priv->blue->val); in ov6550_s_ctrl()
392 priv->red->val); in ov6550_s_ctrl()
396 return ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->val), in ov6550_s_ctrl()
399 return ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->val), in ov6550_s_ctrl()
402 return ov6650_reg_write(client, REG_BRT, ctrl->val); in ov6550_s_ctrl()
404 ret = ov6650_reg_rmw(client, REG_COMB, ctrl->val == in ov6550_s_ctrl()
406 if (!ret && ctrl->val == V4L2_EXPOSURE_MANUAL) in ov6550_s_ctrl()
408 priv->exposure->val); in ov6550_s_ctrl()
411 return ov6650_reg_write(client, REG_GAM1, ctrl->val); in ov6550_s_ctrl()
414 ctrl->val ? COMB_FLIP_V : 0, COMB_FLIP_V); in ov6550_s_ctrl()
417 ctrl->val ? COMB_FLIP_H : 0, COMB_FLIP_H); in ov6550_s_ctrl()
420 return -EINVAL; in ov6550_s_ctrl()
431 if (reg->reg & ~0xff) in ov6650_get_register()
432 return -EINVAL; in ov6650_get_register()
434 reg->size = 1; in ov6650_get_register()
436 ret = ov6650_reg_read(client, reg->reg, &val); in ov6650_get_register()
438 reg->val = (__u64)val; in ov6650_get_register()
448 if (reg->reg & ~0xff || reg->val & ~0xff) in ov6650_set_register()
449 return -EINVAL; in ov6650_set_register()
451 return ov6650_reg_write(client, reg->reg, reg->val); in ov6650_set_register()
462 ret = v4l2_clk_enable(priv->clk); in ov6650_s_power()
464 v4l2_clk_disable(priv->clk); in ov6650_s_power()
476 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) in ov6650_get_selection()
477 return -EINVAL; in ov6650_get_selection()
479 switch (sel->target) { in ov6650_get_selection()
481 sel->r.left = DEF_HSTRT << 1; in ov6650_get_selection()
482 sel->r.top = DEF_VSTRT << 1; in ov6650_get_selection()
483 sel->r.width = W_CIF; in ov6650_get_selection()
484 sel->r.height = H_CIF; in ov6650_get_selection()
487 sel->r = priv->rect; in ov6650_get_selection()
490 return -EINVAL; in ov6650_get_selection()
502 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE || in ov6650_set_selection()
503 sel->target != V4L2_SEL_TGT_CROP) in ov6650_set_selection()
504 return -EINVAL; in ov6650_set_selection()
506 v4l_bound_align_image(&sel->r.width, 2, W_CIF, 1, in ov6650_set_selection()
507 &sel->r.height, 2, H_CIF, 1, 0); in ov6650_set_selection()
508 v4l_bound_align_image(&sel->r.left, DEF_HSTRT << 1, in ov6650_set_selection()
509 (DEF_HSTRT << 1) + W_CIF - (__s32)sel->r.width, 1, in ov6650_set_selection()
510 &sel->r.top, DEF_VSTRT << 1, in ov6650_set_selection()
511 (DEF_VSTRT << 1) + H_CIF - (__s32)sel->r.height, in ov6650_set_selection()
514 ret = ov6650_reg_write(client, REG_HSTRT, sel->r.left >> 1); in ov6650_set_selection()
516 priv->rect.width += priv->rect.left - sel->r.left; in ov6650_set_selection()
517 priv->rect.left = sel->r.left; in ov6650_set_selection()
519 (sel->r.left + sel->r.width) >> 1); in ov6650_set_selection()
522 priv->rect.width = sel->r.width; in ov6650_set_selection()
523 ret = ov6650_reg_write(client, REG_VSTRT, sel->r.top >> 1); in ov6650_set_selection()
526 priv->rect.height += priv->rect.top - sel->r.top; in ov6650_set_selection()
527 priv->rect.top = sel->r.top; in ov6650_set_selection()
529 (sel->r.top + sel->r.height) >> 1); in ov6650_set_selection()
532 priv->rect.height = sel->r.height; in ov6650_set_selection()
541 struct v4l2_mbus_framefmt *mf = &format->format; in ov6650_get_fmt()
545 if (format->pad) in ov6650_get_fmt()
546 return -EINVAL; in ov6650_get_fmt()
552 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in ov6650_get_fmt()
553 mf->width = cfg->try_fmt.width; in ov6650_get_fmt()
554 mf->height = cfg->try_fmt.height; in ov6650_get_fmt()
555 mf->code = cfg->try_fmt.code; in ov6650_get_fmt()
558 mf->width = priv->rect.width >> priv->half_scale; in ov6650_get_fmt()
559 mf->height = priv->rect.height >> priv->half_scale; in ov6650_get_fmt()
560 mf->code = priv->code; in ov6650_get_fmt()
567 return width > rect->width >> 1 || height > rect->height >> 1; in is_unscaled_ok()
570 #define to_clkrc(div) ((div) - 1)
577 bool half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect); in ov6650_s_fmt()
581 .r.left = priv->rect.left + (priv->rect.width >> 1) - in ov6650_s_fmt()
582 (mf->width >> (1 - half_scale)), in ov6650_s_fmt()
583 .r.top = priv->rect.top + (priv->rect.height >> 1) - in ov6650_s_fmt()
584 (mf->height >> (1 - half_scale)), in ov6650_s_fmt()
585 .r.width = mf->width << half_scale, in ov6650_s_fmt()
586 .r.height = mf->height << half_scale, in ov6650_s_fmt()
588 u32 code = mf->code; in ov6650_s_fmt()
595 dev_dbg(&client->dev, "pixel format GREY8_1X8\n"); in ov6650_s_fmt()
600 dev_dbg(&client->dev, "pixel format YUYV8_2X8_LE\n"); in ov6650_s_fmt()
605 dev_dbg(&client->dev, "pixel format YVYU8_2X8_LE (untested)\n"); in ov6650_s_fmt()
610 dev_dbg(&client->dev, "pixel format YUYV8_2X8_BE\n"); in ov6650_s_fmt()
620 dev_dbg(&client->dev, "pixel format YVYU8_2X8_BE (untested)\n"); in ov6650_s_fmt()
630 dev_dbg(&client->dev, "pixel format SBGGR8_1X8 (untested)\n"); in ov6650_s_fmt()
635 dev_err(&client->dev, "Pixel format not handled: 0x%x\n", code); in ov6650_s_fmt()
636 return -EINVAL; in ov6650_s_fmt()
649 dev_dbg(&client->dev, "max resolution: QCIF\n"); in ov6650_s_fmt()
652 dev_dbg(&client->dev, "max resolution: CIF\n"); in ov6650_s_fmt()
660 priv->half_scale = half_scale; in ov6650_s_fmt()
665 priv->code = code; in ov6650_s_fmt()
674 struct v4l2_mbus_framefmt *mf = &format->format; in ov6650_set_fmt()
678 if (format->pad) in ov6650_set_fmt()
679 return -EINVAL; in ov6650_set_fmt()
681 if (is_unscaled_ok(mf->width, mf->height, &priv->rect)) in ov6650_set_fmt()
682 v4l_bound_align_image(&mf->width, 2, W_CIF, 1, in ov6650_set_fmt()
683 &mf->height, 2, H_CIF, 1, 0); in ov6650_set_fmt()
685 switch (mf->code) { in ov6650_set_fmt()
687 mf->code = MEDIA_BUS_FMT_Y8_1X8; in ov6650_set_fmt()
696 mf->code = MEDIA_BUS_FMT_SBGGR8_1X8; in ov6650_set_fmt()
702 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in ov6650_set_fmt()
704 cfg->try_fmt.width = mf->width; in ov6650_set_fmt()
705 cfg->try_fmt.height = mf->height; in ov6650_set_fmt()
706 cfg->try_fmt.code = mf->code; in ov6650_set_fmt()
710 mf->width = cfg->try_fmt.width; in ov6650_set_fmt()
711 mf->height = cfg->try_fmt.height; in ov6650_set_fmt()
712 mf->code = cfg->try_fmt.code; in ov6650_set_fmt()
723 mf->width = priv->rect.width >> priv->half_scale; in ov6650_set_fmt()
724 mf->height = priv->rect.height >> priv->half_scale; in ov6650_set_fmt()
725 mf->code = priv->code; in ov6650_set_fmt()
734 if (code->pad || code->index >= ARRAY_SIZE(ov6650_codes)) in ov6650_enum_mbus_code()
735 return -EINVAL; in ov6650_enum_mbus_code()
737 code->code = ov6650_codes[code->index]; in ov6650_enum_mbus_code()
747 ival->interval = priv->tpf; in ov6650_g_frame_interval()
749 dev_dbg(&client->dev, "Frame interval: %u/%u s\n", in ov6650_g_frame_interval()
750 ival->interval.numerator, ival->interval.denominator); in ov6650_g_frame_interval()
760 struct v4l2_fract *tpf = &ival->interval; in ov6650_s_frame_interval()
763 if (tpf->numerator == 0 || tpf->denominator == 0) in ov6650_s_frame_interval()
766 div = (tpf->numerator * FRAME_RATE_MAX) / tpf->denominator; in ov6650_s_frame_interval()
775 priv->tpf.numerator = div; in ov6650_s_frame_interval()
776 priv->tpf.denominator = FRAME_RATE_MAX; in ov6650_s_frame_interval()
778 *tpf = priv->tpf; in ov6650_s_frame_interval()
789 dev_dbg(&client->dev, "reset\n"); in ov6650_reset()
793 dev_err(&client->dev, in ov6650_reset()
804 dev_dbg(&client->dev, "initializing\n"); in ov6650_prog_dflt()
824 priv->clk = v4l2_clk_get(&client->dev, NULL); in ov6650_video_probe()
825 if (IS_ERR(priv->clk)) { in ov6650_video_probe()
826 ret = PTR_ERR(priv->clk); in ov6650_video_probe()
827 dev_err(&client->dev, "v4l2_clk request err: %d\n", ret); in ov6650_video_probe()
831 rate = v4l2_clk_get_rate(priv->clk); in ov6650_video_probe()
837 dev_info(&client->dev, "using host default clock rate %lukHz\n", in ov6650_video_probe()
842 ret = v4l2_clk_set_rate(priv->clk, ov6650_xclk[i].rate); in ov6650_video_probe()
843 if (ret || v4l2_clk_get_rate(priv->clk) != ov6650_xclk[i].rate) in ov6650_video_probe()
847 dev_info(&client->dev, "using negotiated clock rate %lukHz\n", in ov6650_video_probe()
848 xclk->rate / 1000); in ov6650_video_probe()
852 dev_err(&client->dev, "unable to get supported clock rate\n"); in ov6650_video_probe()
854 ret = -EINVAL; in ov6650_video_probe()
879 dev_err(&client->dev, "Product ID error 0x%02x:0x%02x\n", in ov6650_video_probe()
881 ret = -ENODEV; in ov6650_video_probe()
885 dev_info(&client->dev, in ov6650_video_probe()
891 ret = ov6650_prog_dflt(client, xclk->clkrc); in ov6650_video_probe()
898 ret = v4l2_ctrl_handler_setup(&priv->hdl); in ov6650_video_probe()
905 v4l2_clk_put(priv->clk); in ov6650_video_probe()
940 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH in ov6650_get_mbus_config()
947 cfg->type = V4L2_MBUS_PARALLEL; in ov6650_get_mbus_config()
960 if (cfg->flags & V4L2_MBUS_PCLK_SAMPLE_RISING) in ov6650_set_mbus_config()
962 else if (cfg->flags & V4L2_MBUS_PCLK_SAMPLE_FALLING) in ov6650_set_mbus_config()
967 if (cfg->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) in ov6650_set_mbus_config()
969 else if (cfg->flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) in ov6650_set_mbus_config()
974 if (cfg->flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) in ov6650_set_mbus_config()
976 else if (cfg->flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) in ov6650_set_mbus_config()
1023 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); in ov6650_probe()
1025 return -ENOMEM; in ov6650_probe()
1027 v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops); in ov6650_probe()
1028 v4l2_ctrl_handler_init(&priv->hdl, 13); in ov6650_probe()
1029 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1031 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1033 priv->autogain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1035 priv->gain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1037 priv->autowb = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1039 priv->blue = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1041 priv->red = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1043 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1045 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1047 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1049 priv->autoexposure = v4l2_ctrl_new_std_menu(&priv->hdl, in ov6650_probe()
1052 priv->exposure = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1054 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops, in ov6650_probe()
1057 priv->subdev.ctrl_handler = &priv->hdl; in ov6650_probe()
1058 if (priv->hdl.error) { in ov6650_probe()
1059 ret = priv->hdl.error; in ov6650_probe()
1063 v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true); in ov6650_probe()
1064 v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true); in ov6650_probe()
1065 v4l2_ctrl_auto_cluster(2, &priv->autoexposure, in ov6650_probe()
1068 priv->rect.left = DEF_HSTRT << 1; in ov6650_probe()
1069 priv->rect.top = DEF_VSTRT << 1; in ov6650_probe()
1070 priv->rect.width = W_CIF; in ov6650_probe()
1071 priv->rect.height = H_CIF; in ov6650_probe()
1074 priv->tpf.numerator = GET_CLKRC_DIV(DEF_CLKRC); in ov6650_probe()
1075 priv->tpf.denominator = FRAME_RATE_MAX; in ov6650_probe()
1077 priv->subdev.internal_ops = &ov6650_internal_ops; in ov6650_probe()
1079 ret = v4l2_async_register_subdev(&priv->subdev); in ov6650_probe()
1083 v4l2_ctrl_handler_free(&priv->hdl); in ov6650_probe()
1092 v4l2_clk_put(priv->clk); in ov6650_remove()
1093 v4l2_async_unregister_subdev(&priv->subdev); in ov6650_remove()
1094 v4l2_ctrl_handler_free(&priv->hdl); in ov6650_remove()