Lines Matching +full:charge +full:- +full:ctrl +full:- +full:value
1 // SPDX-License-Identifier: GPL-2.0-only
9 * Copyright 2005-2009 Freescale Semiconductor, Inc. All Rights Reserved.
22 #include <linux/v4l2-mediabus.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-event.h>
27 #include <media/v4l2-subdev.h>
28 #include <media/v4l2-ctrls.h>
29 #include <media/v4l2-image-sizes.h>
163 #define GAIN 0x00 /* AGC - Gain control gain setting */
178 #define REG08 0x08 /* Frame Exposure One-pin Control Pre-charge Row Num */
182 #define COM2_OCAP_Nx_SET(N) (((N) - 1) & 0x03) /* N = [1x .. 4x] */
190 #define AEC 0x10 /* AEC[9:2] Exposure Value */
193 #define CLKRC_DIV_SET(x) (((x) - 1) & 0x1F) /* CLK = XVCLK/(x) */
209 * Automatic gain ceiling - maximum AGC value [7:5]*/
230 #define MIDH 0x1C /* Manufacturer ID byte - high */
231 #define MIDL 0x1D /* Manufacturer ID byte - low */
232 #define AEW 0x24 /* AGC/AEC - Stable operating region (upper limit) */
233 #define AEB 0x25 /* AGC/AEC - Stable operating region (lower limit) */
241 #define YAVG 0x2F /* Y/G Channel Average value */
264 #define BD50_MAX_AEC_STEP_SET(x) VAL_SET((x - 1), 0x0F, 0, 4)
265 #define BD60_MAX_AEC_STEP_SET(x) VAL_SET((x - 1), 0x0F, 0, 0)
266 #define REG5D 0x5D /* AVGsel[7:0], 16-zone average weight option */
267 #define REG5E 0x5E /* AVGsel[15:8], 16-zone average weight option */
268 #define REG5F 0x5F /* AVGsel[23:16], 16-zone average weight option */
269 #define REG60 0x60 /* AVGsel[31:24], 16-zone average weight option */
285 u8 value; member
659 while ((vals->reg_num != 0xff) || (vals->value != 0xff)) { in ov2640_write_array()
661 vals->reg_num, vals->value); in ov2640_write_array()
662 dev_vdbg(&client->dev, "array: 0x%02x, 0x%02x", in ov2640_write_array()
663 vals->reg_num, vals->value); in ov2640_write_array()
682 dev_vdbg(&client->dev, "masks: 0x%02x, 0x%02x", reg, val); in ov2640_mask_set()
702 dev_dbg(&client->dev, "%s: (ret %d)", __func__, ret); in ov2640_reset()
714 static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl) in ov2640_s_ctrl() argument
717 &container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev; in ov2640_s_ctrl()
730 if (!priv->power_count) in ov2640_s_ctrl()
737 switch (ctrl->id) { in ov2640_s_ctrl()
739 val = ctrl->val ? REG04_VFLIP_IMG | REG04_VREF_EN : 0x00; in ov2640_s_ctrl()
744 val = ctrl->val ? REG04_HFLIP_IMG : 0x00; in ov2640_s_ctrl()
747 val = ctrl->val ? COM7_COLOR_BAR_TEST : 0x00; in ov2640_s_ctrl()
751 return -EINVAL; in ov2640_s_ctrl()
761 reg->size = 1; in ov2640_g_register()
762 if (reg->reg > 0xff) in ov2640_g_register()
763 return -EINVAL; in ov2640_g_register()
765 ret = i2c_smbus_read_byte_data(client, reg->reg); in ov2640_g_register()
769 reg->val = ret; in ov2640_g_register()
779 if (reg->reg > 0xff || in ov2640_s_register()
780 reg->val > 0xff) in ov2640_s_register()
781 return -EINVAL; in ov2640_s_register()
783 return i2c_smbus_write_byte_data(client, reg->reg, reg->val); in ov2640_s_register()
790 if (priv->pwdn_gpio) in ov2640_set_power()
791 gpiod_direction_output(priv->pwdn_gpio, !on); in ov2640_set_power()
792 if (on && priv->resetb_gpio) { in ov2640_set_power()
794 gpiod_direction_output(priv->resetb_gpio, 1); in ov2640_set_power()
796 gpiod_set_value(priv->resetb_gpio, 0); in ov2640_set_power()
806 mutex_lock(&priv->lock); in ov2640_s_power()
812 if (priv->power_count == !on) in ov2640_s_power()
814 priv->power_count += on ? 1 : -1; in ov2640_s_power()
815 WARN_ON(priv->power_count < 0); in ov2640_s_power()
816 mutex_unlock(&priv->lock); in ov2640_s_power()
824 int i, default_size = ARRAY_SIZE(ov2640_supported_win_sizes) - 1; in ov2640_select_win()
844 dev_dbg(&client->dev, "%s: Selected cfmt RGB565 BE", __func__); in ov2640_set_params()
848 dev_dbg(&client->dev, "%s: Selected cfmt RGB565 LE", __func__); in ov2640_set_params()
852 dev_dbg(&client->dev, "%s: Selected cfmt YUYV (YUV422)", __func__); in ov2640_set_params()
857 dev_dbg(&client->dev, "%s: Selected cfmt UYVY", __func__); in ov2640_set_params()
861 dev_dbg(&client->dev, "%s: Selected cfmt YVYU", __func__); in ov2640_set_params()
865 dev_dbg(&client->dev, "%s: Selected cfmt VYUY", __func__); in ov2640_set_params()
874 dev_dbg(&client->dev, "%s: Init default", __func__); in ov2640_set_params()
880 dev_dbg(&client->dev, "%s: Set size to %s", __func__, win->name); in ov2640_set_params()
886 ret = ov2640_write_array(client, win->regs); in ov2640_set_params()
891 dev_dbg(&client->dev, "%s: Set cfmt", __func__); in ov2640_set_params()
909 dev_err(&client->dev, "%s: Error %d", __func__, ret); in ov2640_set_params()
919 struct v4l2_mbus_framefmt *mf = &format->format; in ov2640_get_fmt()
923 if (format->pad) in ov2640_get_fmt()
924 return -EINVAL; in ov2640_get_fmt()
926 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in ov2640_get_fmt()
929 format->format = *mf; in ov2640_get_fmt()
932 return -EINVAL; in ov2640_get_fmt()
936 mf->width = priv->win->width; in ov2640_get_fmt()
937 mf->height = priv->win->height; in ov2640_get_fmt()
938 mf->code = priv->cfmt_code; in ov2640_get_fmt()
939 mf->colorspace = V4L2_COLORSPACE_SRGB; in ov2640_get_fmt()
940 mf->field = V4L2_FIELD_NONE; in ov2640_get_fmt()
941 mf->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in ov2640_get_fmt()
942 mf->quantization = V4L2_QUANTIZATION_DEFAULT; in ov2640_get_fmt()
943 mf->xfer_func = V4L2_XFER_FUNC_DEFAULT; in ov2640_get_fmt()
952 struct v4l2_mbus_framefmt *mf = &format->format; in ov2640_set_fmt()
958 if (format->pad) in ov2640_set_fmt()
959 return -EINVAL; in ov2640_set_fmt()
961 mutex_lock(&priv->lock); in ov2640_set_fmt()
964 win = ov2640_select_win(mf->width, mf->height); in ov2640_set_fmt()
965 mf->width = win->width; in ov2640_set_fmt()
966 mf->height = win->height; in ov2640_set_fmt()
968 mf->field = V4L2_FIELD_NONE; in ov2640_set_fmt()
969 mf->colorspace = V4L2_COLORSPACE_SRGB; in ov2640_set_fmt()
970 mf->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in ov2640_set_fmt()
971 mf->quantization = V4L2_QUANTIZATION_DEFAULT; in ov2640_set_fmt()
972 mf->xfer_func = V4L2_XFER_FUNC_DEFAULT; in ov2640_set_fmt()
974 switch (mf->code) { in ov2640_set_fmt()
983 mf->code = MEDIA_BUS_FMT_UYVY8_2X8; in ov2640_set_fmt()
987 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) { in ov2640_set_fmt()
990 if (priv->streaming) { in ov2640_set_fmt()
991 ret = -EBUSY; in ov2640_set_fmt()
995 priv->win = win; in ov2640_set_fmt()
997 priv->cfmt_code = mf->code; in ov2640_set_fmt()
999 cfg->try_fmt = *mf; in ov2640_set_fmt()
1002 mutex_unlock(&priv->lock); in ov2640_set_fmt()
1016 try_fmt->width = win->width; in ov2640_init_cfg()
1017 try_fmt->height = win->height; in ov2640_init_cfg()
1018 try_fmt->code = MEDIA_BUS_FMT_UYVY8_2X8; in ov2640_init_cfg()
1019 try_fmt->colorspace = V4L2_COLORSPACE_SRGB; in ov2640_init_cfg()
1020 try_fmt->field = V4L2_FIELD_NONE; in ov2640_init_cfg()
1021 try_fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in ov2640_init_cfg()
1022 try_fmt->quantization = V4L2_QUANTIZATION_DEFAULT; in ov2640_init_cfg()
1023 try_fmt->xfer_func = V4L2_XFER_FUNC_DEFAULT; in ov2640_init_cfg()
1032 if (code->pad || code->index >= ARRAY_SIZE(ov2640_codes)) in ov2640_enum_mbus_code()
1033 return -EINVAL; in ov2640_enum_mbus_code()
1035 code->code = ov2640_codes[code->index]; in ov2640_enum_mbus_code()
1043 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) in ov2640_get_selection()
1044 return -EINVAL; in ov2640_get_selection()
1046 switch (sel->target) { in ov2640_get_selection()
1049 sel->r.left = 0; in ov2640_get_selection()
1050 sel->r.top = 0; in ov2640_get_selection()
1051 sel->r.width = UXGA_WIDTH; in ov2640_get_selection()
1052 sel->r.height = UXGA_HEIGHT; in ov2640_get_selection()
1055 return -EINVAL; in ov2640_get_selection()
1065 mutex_lock(&priv->lock); in ov2640_s_stream()
1066 if (priv->streaming == !on) { in ov2640_s_stream()
1068 ret = ov2640_set_params(client, priv->win, in ov2640_s_stream()
1069 priv->cfmt_code); in ov2640_s_stream()
1071 ret = __v4l2_ctrl_handler_setup(&priv->hdl); in ov2640_s_stream()
1075 priv->streaming = on; in ov2640_s_stream()
1076 mutex_unlock(&priv->lock); in ov2640_s_stream()
1088 ret = ov2640_s_power(&priv->subdev, 1); in ov2640_video_probe()
1106 dev_err(&client->dev, in ov2640_video_probe()
1108 ret = -ENODEV; in ov2640_video_probe()
1112 dev_info(&client->dev, in ov2640_video_probe()
1117 ov2640_s_power(&priv->subdev, 0); in ov2640_video_probe()
1160 priv->resetb_gpio = devm_gpiod_get_optional(&client->dev, "resetb", in ov2640_probe_dt()
1163 if (!priv->resetb_gpio) in ov2640_probe_dt()
1164 dev_dbg(&client->dev, "resetb gpio is not assigned!\n"); in ov2640_probe_dt()
1166 ret = PTR_ERR_OR_ZERO(priv->resetb_gpio); in ov2640_probe_dt()
1167 if (ret && ret != -ENOSYS) { in ov2640_probe_dt()
1168 dev_dbg(&client->dev, in ov2640_probe_dt()
1174 priv->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "pwdn", in ov2640_probe_dt()
1177 if (!priv->pwdn_gpio) in ov2640_probe_dt()
1178 dev_dbg(&client->dev, "pwdn gpio is not assigned!\n"); in ov2640_probe_dt()
1180 ret = PTR_ERR_OR_ZERO(priv->pwdn_gpio); in ov2640_probe_dt()
1181 if (ret && ret != -ENOSYS) { in ov2640_probe_dt()
1182 dev_dbg(&client->dev, in ov2640_probe_dt()
1196 struct i2c_adapter *adapter = client->adapter; in ov2640_probe()
1200 dev_err(&adapter->dev, in ov2640_probe()
1201 "OV2640: I2C-Adapter doesn't support SMBUS\n"); in ov2640_probe()
1202 return -EIO; in ov2640_probe()
1205 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); in ov2640_probe()
1207 return -ENOMEM; in ov2640_probe()
1209 if (client->dev.of_node) { in ov2640_probe()
1210 priv->clk = devm_clk_get(&client->dev, "xvclk"); in ov2640_probe()
1211 if (IS_ERR(priv->clk)) in ov2640_probe()
1212 return PTR_ERR(priv->clk); in ov2640_probe()
1213 ret = clk_prepare_enable(priv->clk); in ov2640_probe()
1222 priv->win = ov2640_select_win(SVGA_WIDTH, SVGA_HEIGHT); in ov2640_probe()
1223 priv->cfmt_code = MEDIA_BUS_FMT_UYVY8_2X8; in ov2640_probe()
1225 v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops); in ov2640_probe()
1226 priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov2640_probe()
1228 mutex_init(&priv->lock); in ov2640_probe()
1229 v4l2_ctrl_handler_init(&priv->hdl, 3); in ov2640_probe()
1230 priv->hdl.lock = &priv->lock; in ov2640_probe()
1231 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops, in ov2640_probe()
1233 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops, in ov2640_probe()
1235 v4l2_ctrl_new_std_menu_items(&priv->hdl, &ov2640_ctrl_ops, in ov2640_probe()
1237 ARRAY_SIZE(ov2640_test_pattern_menu) - 1, 0, 0, in ov2640_probe()
1239 priv->subdev.ctrl_handler = &priv->hdl; in ov2640_probe()
1240 if (priv->hdl.error) { in ov2640_probe()
1241 ret = priv->hdl.error; in ov2640_probe()
1245 priv->pad.flags = MEDIA_PAD_FL_SOURCE; in ov2640_probe()
1246 priv->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov2640_probe()
1247 ret = media_entity_pads_init(&priv->subdev.entity, 1, &priv->pad); in ov2640_probe()
1256 ret = v4l2_async_register_subdev(&priv->subdev); in ov2640_probe()
1260 dev_info(&adapter->dev, "OV2640 Probed\n"); in ov2640_probe()
1265 media_entity_cleanup(&priv->subdev.entity); in ov2640_probe()
1267 v4l2_ctrl_handler_free(&priv->hdl); in ov2640_probe()
1268 mutex_destroy(&priv->lock); in ov2640_probe()
1270 clk_disable_unprepare(priv->clk); in ov2640_probe()
1278 v4l2_async_unregister_subdev(&priv->subdev); in ov2640_remove()
1279 v4l2_ctrl_handler_free(&priv->hdl); in ov2640_remove()
1280 mutex_destroy(&priv->lock); in ov2640_remove()
1281 media_entity_cleanup(&priv->subdev.entity); in ov2640_remove()
1282 v4l2_device_unregister_subdev(&priv->subdev); in ov2640_remove()
1283 clk_disable_unprepare(priv->clk); in ov2640_remove()