Lines Matching +full:gpio +full:- +full:ctrl1
1 // SPDX-License-Identifier: GPL-2.0-only
9 * Copyright 2005-2009 Freescale Semiconductor, Inc. All Rights Reserved.
19 #include <linux/gpio/consumer.h>
20 #include <linux/v4l2-mediabus.h>
23 #include <media/v4l2-device.h>
24 #include <media/v4l2-event.h>
25 #include <media/v4l2-subdev.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-image-sizes.h>
96 #define CTRL1 0xC3 /* DSP Module enable 1 */ macro
161 #define GAIN 0x00 /* AGC - Gain control gain setting */
176 #define REG08 0x08 /* Frame Exposure One-pin Control Pre-charge Row Num */
180 #define COM2_OCAP_Nx_SET(N) (((N) - 1) & 0x03) /* N = [1x .. 4x] */
191 #define CLKRC_DIV_SET(x) (((x) - 1) & 0x1F) /* CLK = XVCLK/(x) */
207 * Automatic gain ceiling - maximum AGC value [7:5]*/
228 #define MIDH 0x1C /* Manufacturer ID byte - high */
229 #define MIDL 0x1D /* Manufacturer ID byte - low */
230 #define AEW 0x24 /* AGC/AEC - Stable operating region (upper limit) */
231 #define AEB 0x25 /* AGC/AEC - Stable operating region (lower limit) */
262 #define BD50_MAX_AEC_STEP_SET(x) VAL_SET((x - 1), 0x0F, 0, 4)
263 #define BD60_MAX_AEC_STEP_SET(x) VAL_SET((x - 1), 0x0F, 0, 0)
264 #define REG5D 0x5D /* AVGsel[7:0], 16-zone average weight option */
265 #define REG5E 0x5E /* AVGsel[15:8], 16-zone average weight option */
266 #define REG5F 0x5F /* AVGsel[23:16], 16-zone average weight option */
267 #define REG60 0x60 /* AVGsel[31:24], 16-zone average weight option */
655 while ((vals->reg_num != 0xff) || (vals->value != 0xff)) { in ov2640_write_array()
657 vals->reg_num, vals->value); in ov2640_write_array()
658 dev_vdbg(&client->dev, "array: 0x%02x, 0x%02x", in ov2640_write_array()
659 vals->reg_num, vals->value); in ov2640_write_array()
678 dev_vdbg(&client->dev, "masks: 0x%02x, 0x%02x", reg, val); in ov2640_mask_set()
698 dev_dbg(&client->dev, "%s: (ret %d)", __func__, ret); in ov2640_reset()
713 &container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev; in ov2640_s_ctrl()
726 if (!priv->power_count) in ov2640_s_ctrl()
733 switch (ctrl->id) { in ov2640_s_ctrl()
735 val = ctrl->val ? REG04_VFLIP_IMG | REG04_VREF_EN : 0x00; in ov2640_s_ctrl()
740 val = ctrl->val ? REG04_HFLIP_IMG : 0x00; in ov2640_s_ctrl()
743 val = ctrl->val ? COM7_COLOR_BAR_TEST : 0x00; in ov2640_s_ctrl()
747 return -EINVAL; in ov2640_s_ctrl()
757 reg->size = 1; in ov2640_g_register()
758 if (reg->reg > 0xff) in ov2640_g_register()
759 return -EINVAL; in ov2640_g_register()
761 ret = i2c_smbus_read_byte_data(client, reg->reg); in ov2640_g_register()
765 reg->val = ret; in ov2640_g_register()
775 if (reg->reg > 0xff || in ov2640_s_register()
776 reg->val > 0xff) in ov2640_s_register()
777 return -EINVAL; in ov2640_s_register()
779 return i2c_smbus_write_byte_data(client, reg->reg, reg->val); in ov2640_s_register()
786 if (priv->pwdn_gpio) in ov2640_set_power()
787 gpiod_direction_output(priv->pwdn_gpio, !on); in ov2640_set_power()
788 if (on && priv->resetb_gpio) { in ov2640_set_power()
790 gpiod_direction_output(priv->resetb_gpio, 1); in ov2640_set_power()
792 gpiod_set_value(priv->resetb_gpio, 0); in ov2640_set_power()
802 mutex_lock(&priv->lock); in ov2640_s_power()
808 if (priv->power_count == !on) in ov2640_s_power()
810 priv->power_count += on ? 1 : -1; in ov2640_s_power()
811 WARN_ON(priv->power_count < 0); in ov2640_s_power()
812 mutex_unlock(&priv->lock); in ov2640_s_power()
820 int i, default_size = ARRAY_SIZE(ov2640_supported_win_sizes) - 1; in ov2640_select_win()
840 dev_dbg(&client->dev, "%s: Selected cfmt RGB565 BE", __func__); in ov2640_set_params()
844 dev_dbg(&client->dev, "%s: Selected cfmt RGB565 LE", __func__); in ov2640_set_params()
848 dev_dbg(&client->dev, "%s: Selected cfmt YUYV (YUV422)", __func__); in ov2640_set_params()
853 dev_dbg(&client->dev, "%s: Selected cfmt UYVY", __func__); in ov2640_set_params()
857 dev_dbg(&client->dev, "%s: Selected cfmt YVYU", __func__); in ov2640_set_params()
861 dev_dbg(&client->dev, "%s: Selected cfmt VYUY", __func__); in ov2640_set_params()
870 dev_dbg(&client->dev, "%s: Init default", __func__); in ov2640_set_params()
876 dev_dbg(&client->dev, "%s: Set size to %s", __func__, win->name); in ov2640_set_params()
882 ret = ov2640_write_array(client, win->regs); in ov2640_set_params()
887 dev_dbg(&client->dev, "%s: Set cfmt", __func__); in ov2640_set_params()
905 dev_err(&client->dev, "%s: Error %d", __func__, ret); in ov2640_set_params()
915 struct v4l2_mbus_framefmt *mf = &format->format; in ov2640_get_fmt()
919 if (format->pad) in ov2640_get_fmt()
920 return -EINVAL; in ov2640_get_fmt()
922 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in ov2640_get_fmt()
924 format->format = *mf; in ov2640_get_fmt()
928 mf->width = priv->win->width; in ov2640_get_fmt()
929 mf->height = priv->win->height; in ov2640_get_fmt()
930 mf->code = priv->cfmt_code; in ov2640_get_fmt()
931 mf->colorspace = V4L2_COLORSPACE_SRGB; in ov2640_get_fmt()
932 mf->field = V4L2_FIELD_NONE; in ov2640_get_fmt()
933 mf->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in ov2640_get_fmt()
934 mf->quantization = V4L2_QUANTIZATION_DEFAULT; in ov2640_get_fmt()
935 mf->xfer_func = V4L2_XFER_FUNC_DEFAULT; in ov2640_get_fmt()
944 struct v4l2_mbus_framefmt *mf = &format->format; in ov2640_set_fmt()
950 if (format->pad) in ov2640_set_fmt()
951 return -EINVAL; in ov2640_set_fmt()
953 mutex_lock(&priv->lock); in ov2640_set_fmt()
956 win = ov2640_select_win(mf->width, mf->height); in ov2640_set_fmt()
957 mf->width = win->width; in ov2640_set_fmt()
958 mf->height = win->height; in ov2640_set_fmt()
960 mf->field = V4L2_FIELD_NONE; in ov2640_set_fmt()
961 mf->colorspace = V4L2_COLORSPACE_SRGB; in ov2640_set_fmt()
962 mf->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in ov2640_set_fmt()
963 mf->quantization = V4L2_QUANTIZATION_DEFAULT; in ov2640_set_fmt()
964 mf->xfer_func = V4L2_XFER_FUNC_DEFAULT; in ov2640_set_fmt()
966 switch (mf->code) { in ov2640_set_fmt()
975 mf->code = MEDIA_BUS_FMT_UYVY8_2X8; in ov2640_set_fmt()
979 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) { in ov2640_set_fmt()
982 if (priv->streaming) { in ov2640_set_fmt()
983 ret = -EBUSY; in ov2640_set_fmt()
987 priv->win = win; in ov2640_set_fmt()
989 priv->cfmt_code = mf->code; in ov2640_set_fmt()
994 mutex_unlock(&priv->lock); in ov2640_set_fmt()
1007 try_fmt->width = win->width; in ov2640_init_state()
1008 try_fmt->height = win->height; in ov2640_init_state()
1009 try_fmt->code = MEDIA_BUS_FMT_UYVY8_2X8; in ov2640_init_state()
1010 try_fmt->colorspace = V4L2_COLORSPACE_SRGB; in ov2640_init_state()
1011 try_fmt->field = V4L2_FIELD_NONE; in ov2640_init_state()
1012 try_fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in ov2640_init_state()
1013 try_fmt->quantization = V4L2_QUANTIZATION_DEFAULT; in ov2640_init_state()
1014 try_fmt->xfer_func = V4L2_XFER_FUNC_DEFAULT; in ov2640_init_state()
1023 if (code->pad || code->index >= ARRAY_SIZE(ov2640_codes)) in ov2640_enum_mbus_code()
1024 return -EINVAL; in ov2640_enum_mbus_code()
1026 code->code = ov2640_codes[code->index]; in ov2640_enum_mbus_code()
1034 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) in ov2640_get_selection()
1035 return -EINVAL; in ov2640_get_selection()
1037 switch (sel->target) { in ov2640_get_selection()
1040 sel->r.left = 0; in ov2640_get_selection()
1041 sel->r.top = 0; in ov2640_get_selection()
1042 sel->r.width = UXGA_WIDTH; in ov2640_get_selection()
1043 sel->r.height = UXGA_HEIGHT; in ov2640_get_selection()
1046 return -EINVAL; in ov2640_get_selection()
1056 mutex_lock(&priv->lock); in ov2640_s_stream()
1057 if (priv->streaming == !on) { in ov2640_s_stream()
1059 ret = ov2640_set_params(client, priv->win, in ov2640_s_stream()
1060 priv->cfmt_code); in ov2640_s_stream()
1062 ret = __v4l2_ctrl_handler_setup(&priv->hdl); in ov2640_s_stream()
1066 priv->streaming = on; in ov2640_s_stream()
1067 mutex_unlock(&priv->lock); in ov2640_s_stream()
1079 ret = ov2640_s_power(&priv->subdev, 1); in ov2640_video_probe()
1097 dev_err(&client->dev, in ov2640_video_probe()
1099 ret = -ENODEV; in ov2640_video_probe()
1103 dev_info(&client->dev, in ov2640_video_probe()
1108 ov2640_s_power(&priv->subdev, 0); in ov2640_video_probe()
1153 /* Request the reset GPIO deasserted */ in ov2640_probe_dt()
1154 priv->resetb_gpio = devm_gpiod_get_optional(&client->dev, "resetb", in ov2640_probe_dt()
1157 if (!priv->resetb_gpio) in ov2640_probe_dt()
1158 dev_dbg(&client->dev, "resetb gpio is not assigned!\n"); in ov2640_probe_dt()
1160 ret = PTR_ERR_OR_ZERO(priv->resetb_gpio); in ov2640_probe_dt()
1161 if (ret && ret != -ENOSYS) { in ov2640_probe_dt()
1162 dev_dbg(&client->dev, in ov2640_probe_dt()
1163 "Error %d while getting resetb gpio\n", ret); in ov2640_probe_dt()
1167 /* Request the power down GPIO asserted */ in ov2640_probe_dt()
1168 priv->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "pwdn", in ov2640_probe_dt()
1171 if (!priv->pwdn_gpio) in ov2640_probe_dt()
1172 dev_dbg(&client->dev, "pwdn gpio is not assigned!\n"); in ov2640_probe_dt()
1174 ret = PTR_ERR_OR_ZERO(priv->pwdn_gpio); in ov2640_probe_dt()
1175 if (ret && ret != -ENOSYS) { in ov2640_probe_dt()
1176 dev_dbg(&client->dev, in ov2640_probe_dt()
1177 "Error %d while getting pwdn gpio\n", ret); in ov2640_probe_dt()
1190 struct i2c_adapter *adapter = client->adapter; in ov2640_probe()
1194 dev_err(&adapter->dev, in ov2640_probe()
1195 "OV2640: I2C-Adapter doesn't support SMBUS\n"); in ov2640_probe()
1196 return -EIO; in ov2640_probe()
1199 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); in ov2640_probe()
1201 return -ENOMEM; in ov2640_probe()
1203 if (client->dev.of_node) { in ov2640_probe()
1204 priv->clk = devm_clk_get_enabled(&client->dev, "xvclk"); in ov2640_probe()
1205 if (IS_ERR(priv->clk)) in ov2640_probe()
1206 return PTR_ERR(priv->clk); in ov2640_probe()
1213 priv->win = ov2640_select_win(SVGA_WIDTH, SVGA_HEIGHT); in ov2640_probe()
1214 priv->cfmt_code = MEDIA_BUS_FMT_UYVY8_2X8; in ov2640_probe()
1216 v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops); in ov2640_probe()
1217 priv->subdev.internal_ops = &ov2640_internal_ops; in ov2640_probe()
1218 priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov2640_probe()
1220 mutex_init(&priv->lock); in ov2640_probe()
1221 v4l2_ctrl_handler_init(&priv->hdl, 3); in ov2640_probe()
1222 priv->hdl.lock = &priv->lock; in ov2640_probe()
1223 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops, in ov2640_probe()
1225 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops, in ov2640_probe()
1227 v4l2_ctrl_new_std_menu_items(&priv->hdl, &ov2640_ctrl_ops, in ov2640_probe()
1229 ARRAY_SIZE(ov2640_test_pattern_menu) - 1, 0, 0, in ov2640_probe()
1231 priv->subdev.ctrl_handler = &priv->hdl; in ov2640_probe()
1232 if (priv->hdl.error) { in ov2640_probe()
1233 ret = priv->hdl.error; in ov2640_probe()
1236 priv->pad.flags = MEDIA_PAD_FL_SOURCE; in ov2640_probe()
1237 priv->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov2640_probe()
1238 ret = media_entity_pads_init(&priv->subdev.entity, 1, &priv->pad); in ov2640_probe()
1246 ret = v4l2_async_register_subdev(&priv->subdev); in ov2640_probe()
1250 dev_info(&adapter->dev, "OV2640 Probed\n"); in ov2640_probe()
1255 media_entity_cleanup(&priv->subdev.entity); in ov2640_probe()
1257 v4l2_ctrl_handler_free(&priv->hdl); in ov2640_probe()
1258 mutex_destroy(&priv->lock); in ov2640_probe()
1266 v4l2_async_unregister_subdev(&priv->subdev); in ov2640_remove()
1267 v4l2_ctrl_handler_free(&priv->hdl); in ov2640_remove()
1268 mutex_destroy(&priv->lock); in ov2640_remove()
1269 media_entity_cleanup(&priv->subdev.entity); in ov2640_remove()
1270 v4l2_device_unregister_subdev(&priv->subdev); in ov2640_remove()