Lines Matching +full:1 +full:x64 +full:- +full:bit

1 // SPDX-License-Identifier: GPL-2.0
5 * Based on Samsung S5K6AAFX SXGA 1/6" 1.3M CMOS Image Sensor driver
9 * Copyright (C) 2006-7 Jonathan Corbet <corbet@lwn.net>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-device.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-fwnode.h>
29 #include <media/v4l2-image-sizes.h>
30 #include <media/v4l2-mediabus.h>
39 #define MIPI_CTRL00_CLOCK_LANE_GATE BIT(5)
40 #define MIPI_CTRL00_LINE_SYNC_ENABLE BIT(4)
41 #define MIPI_CTRL00_BUS_IDLE BIT(2)
42 #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0)
80 #define OV5647_EXPOSURE_STEP 1
179 {0x3708, 0x64},
200 {0x3620, 0x64},
268 {0x3708, 0x64},
289 {0x3620, 0x64},
374 {0x3620, 0x64},
442 {0x3708, 0x64},
460 {0x3620, 0x64},
507 /* 2592x1944 full resolution full FOV 10-bit mode. */
528 /* 1080p30 10-bit mode. Full resolution centre-cropped down to 1080p. */
549 /* 2x2 binned full FOV 10-bit mode. */
570 /* 10-bit VGA full FOV 60fps. 2x2 binned and subsampled down to VGA. */
605 dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n", in ov5647_write16()
621 dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n", in ov5647_write()
636 msg[0].addr = client->addr; in ov5647_read()
637 msg[0].flags = client->flags; in ov5647_read()
641 msg[1].addr = client->addr; in ov5647_read()
642 msg[1].flags = client->flags | I2C_M_RD; in ov5647_read()
643 msg[1].buf = buf; in ov5647_read()
644 msg[1].len = 1; in ov5647_read()
646 ret = i2c_transfer(client->adapter, msg, 2); in ov5647_read()
648 dev_err(&client->dev, "%s: i2c read error, reg: %x = %d\n", in ov5647_read()
650 return ret >= 0 ? -EINVAL : ret; in ov5647_read()
698 ret = ov5647_write_array(sd, sensor->mode->reg_list, in ov5647_set_mode()
699 sensor->mode->num_regs); in ov5647_set_mode()
701 dev_err(&client->dev, "write sensor default regs error\n"); in ov5647_set_mode()
714 dev_err(&client->dev, "Device was in SW standby"); in ov5647_set_mode()
732 dev_err(&client->dev, "Failed to program sensor mode: %d\n", ret); in ov5647_stream_on()
737 ret = __v4l2_ctrl_handler_setup(sd->ctrl_handler); in ov5647_stream_on()
741 if (sensor->clock_ncont) in ov5647_stream_on()
780 if (sensor->pwdn) { in ov5647_power_on()
781 gpiod_set_value_cansleep(sensor->pwdn, 0); in ov5647_power_on()
785 ret = clk_prepare_enable(sensor->xclk); in ov5647_power_on()
791 ret = ov5647_write_array(&sensor->sd, sensor_oe_enable_regs, in ov5647_power_on()
798 /* Stream off to coax lanes into LP-11 state. */ in ov5647_power_on()
799 ret = ov5647_stream_off(&sensor->sd); in ov5647_power_on()
808 clk_disable_unprepare(sensor->xclk); in ov5647_power_on()
810 gpiod_set_value_cansleep(sensor->pwdn, 1); in ov5647_power_on()
823 ret = ov5647_write_array(&sensor->sd, sensor_oe_disable_regs, in ov5647_power_off()
829 ret = ov5647_read(&sensor->sd, OV5647_SW_STANDBY, &rdval); in ov5647_power_off()
834 ret = ov5647_write(&sensor->sd, OV5647_SW_STANDBY, rdval); in ov5647_power_off()
838 clk_disable_unprepare(sensor->xclk); in ov5647_power_off()
839 gpiod_set_value_cansleep(sensor->pwdn, 1); in ov5647_power_off()
851 ret = ov5647_read(sd, reg->reg & 0xff, &val); in ov5647_sensor_get_register()
855 reg->val = val; in ov5647_sensor_get_register()
856 reg->size = 1; in ov5647_sensor_get_register()
864 return ov5647_write(sd, reg->reg & 0xff, reg->val & 0xff); in ov5647_sensor_set_register()
887 return &ov5647->mode->crop; in __ov5647_get_pad_crop()
899 mutex_lock(&sensor->lock); in ov5647_s_stream()
902 ret = pm_runtime_resume_and_get(&client->dev); in ov5647_s_stream()
908 dev_err(&client->dev, "stream start failed: %d\n", ret); in ov5647_s_stream()
914 dev_err(&client->dev, "stream stop failed: %d\n", ret); in ov5647_s_stream()
917 pm_runtime_put(&client->dev); in ov5647_s_stream()
920 mutex_unlock(&sensor->lock); in ov5647_s_stream()
925 pm_runtime_put(&client->dev); in ov5647_s_stream()
927 mutex_unlock(&sensor->lock); in ov5647_s_stream()
940 if (code->index > 0) in ov5647_enum_mbus_code()
941 return -EINVAL; in ov5647_enum_mbus_code()
943 code->code = MEDIA_BUS_FMT_SBGGR10_1X10; in ov5647_enum_mbus_code()
954 if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10 || in ov5647_enum_frame_size()
955 fse->index >= ARRAY_SIZE(ov5647_modes)) in ov5647_enum_frame_size()
956 return -EINVAL; in ov5647_enum_frame_size()
958 fmt = &ov5647_modes[fse->index].format; in ov5647_enum_frame_size()
959 fse->min_width = fmt->width; in ov5647_enum_frame_size()
960 fse->max_width = fmt->width; in ov5647_enum_frame_size()
961 fse->min_height = fmt->height; in ov5647_enum_frame_size()
962 fse->max_height = fmt->height; in ov5647_enum_frame_size()
971 struct v4l2_mbus_framefmt *fmt = &format->format; in ov5647_get_pad_fmt()
975 mutex_lock(&sensor->lock); in ov5647_get_pad_fmt()
976 switch (format->which) { in ov5647_get_pad_fmt()
979 format->pad); in ov5647_get_pad_fmt()
982 sensor_format = &sensor->mode->format; in ov5647_get_pad_fmt()
987 mutex_unlock(&sensor->lock); in ov5647_get_pad_fmt()
996 struct v4l2_mbus_framefmt *fmt = &format->format; in ov5647_set_pad_fmt()
1002 fmt->width, fmt->height); in ov5647_set_pad_fmt()
1005 mutex_lock(&sensor->lock); in ov5647_set_pad_fmt()
1006 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in ov5647_set_pad_fmt()
1007 *v4l2_subdev_state_get_format(sd_state, format->pad) = mode->format; in ov5647_set_pad_fmt()
1012 sensor->mode = mode; in ov5647_set_pad_fmt()
1013 __v4l2_ctrl_modify_range(sensor->pixel_rate, mode->pixel_rate, in ov5647_set_pad_fmt()
1014 mode->pixel_rate, 1, mode->pixel_rate); in ov5647_set_pad_fmt()
1016 hblank = mode->hts - mode->format.width; in ov5647_set_pad_fmt()
1017 __v4l2_ctrl_modify_range(sensor->hblank, hblank, hblank, 1, in ov5647_set_pad_fmt()
1020 vblank = mode->vts - mode->format.height; in ov5647_set_pad_fmt()
1021 __v4l2_ctrl_modify_range(sensor->vblank, OV5647_VBLANK_MIN, in ov5647_set_pad_fmt()
1022 OV5647_VTS_MAX - mode->format.height, in ov5647_set_pad_fmt()
1023 1, vblank); in ov5647_set_pad_fmt()
1024 __v4l2_ctrl_s_ctrl(sensor->vblank, vblank); in ov5647_set_pad_fmt()
1026 exposure_max = mode->vts - 4; in ov5647_set_pad_fmt()
1028 __v4l2_ctrl_modify_range(sensor->exposure, in ov5647_set_pad_fmt()
1029 sensor->exposure->minimum, in ov5647_set_pad_fmt()
1030 exposure_max, sensor->exposure->step, in ov5647_set_pad_fmt()
1033 *fmt = mode->format; in ov5647_set_pad_fmt()
1034 mutex_unlock(&sensor->lock); in ov5647_set_pad_fmt()
1043 switch (sel->target) { in ov5647_get_selection()
1047 mutex_lock(&sensor->lock); in ov5647_get_selection()
1048 sel->r = *__ov5647_get_pad_crop(sensor, sd_state, sel->pad, in ov5647_get_selection()
1049 sel->which); in ov5647_get_selection()
1050 mutex_unlock(&sensor->lock); in ov5647_get_selection()
1056 sel->r.top = 0; in ov5647_get_selection()
1057 sel->r.left = 0; in ov5647_get_selection()
1058 sel->r.width = OV5647_NATIVE_WIDTH; in ov5647_get_selection()
1059 sel->r.height = OV5647_NATIVE_HEIGHT; in ov5647_get_selection()
1065 sel->r.top = OV5647_PIXEL_ARRAY_TOP; in ov5647_get_selection()
1066 sel->r.left = OV5647_PIXEL_ARRAY_LEFT; in ov5647_get_selection()
1067 sel->r.width = OV5647_PIXEL_ARRAY_WIDTH; in ov5647_get_selection()
1068 sel->r.height = OV5647_PIXEL_ARRAY_HEIGHT; in ov5647_get_selection()
1073 return -EINVAL; in ov5647_get_selection()
1105 dev_err(&client->dev, "ID High expected 0x56 got %x", read); in ov5647_detect()
1106 return -ENODEV; in ov5647_detect()
1114 dev_err(&client->dev, "ID Low expected 0x47 got %x", read); in ov5647_detect()
1115 return -ENODEV; in ov5647_detect()
1124 v4l2_subdev_state_get_format(fh->state, 0); in ov5647_open()
1125 struct v4l2_rect *crop = v4l2_subdev_state_get_crop(fh->state, 0); in ov5647_open()
1127 crop->left = OV5647_PIXEL_ARRAY_LEFT; in ov5647_open()
1128 crop->top = OV5647_PIXEL_ARRAY_TOP; in ov5647_open()
1129 crop->width = OV5647_PIXEL_ARRAY_WIDTH; in ov5647_open()
1130 crop->height = OV5647_PIXEL_ARRAY_HEIGHT; in ov5647_open()
1143 return ov5647_write(sd, OV5647_REG_AWB, val ? 1 : 0); in ov5647_s_auto_white_balance()
1151 /* Non-zero turns on AGC by clearing bit 1.*/ in ov5647_s_autogain()
1156 return ov5647_write(sd, OV5647_REG_AEC_AGC, val ? reg & ~BIT(1) in ov5647_s_autogain()
1157 : reg | BIT(1)); in ov5647_s_autogain()
1167 * clearing bit 0. in ov5647_s_exposure_auto()
1174 val == V4L2_EXPOSURE_MANUAL ? reg | BIT(0) in ov5647_s_exposure_auto()
1175 : reg & ~BIT(0)); in ov5647_s_exposure_auto()
1211 struct ov5647 *sensor = container_of(ctrl->handler, in ov5647_s_ctrl()
1213 struct v4l2_subdev *sd = &sensor->sd; in ov5647_s_ctrl()
1220 if (ctrl->id == V4L2_CID_VBLANK) { in ov5647_s_ctrl()
1224 exposure_max = sensor->mode->format.height + ctrl->val - 4; in ov5647_s_ctrl()
1226 __v4l2_ctrl_modify_range(sensor->exposure, in ov5647_s_ctrl()
1227 sensor->exposure->minimum, in ov5647_s_ctrl()
1228 exposure_max, sensor->exposure->step, in ov5647_s_ctrl()
1235 * at s_stream(1) time. in ov5647_s_ctrl()
1237 if (pm_runtime_get_if_in_use(&client->dev) == 0) in ov5647_s_ctrl()
1240 switch (ctrl->id) { in ov5647_s_ctrl()
1242 ret = ov5647_s_auto_white_balance(sd, ctrl->val); in ov5647_s_ctrl()
1245 ret = ov5647_s_autogain(sd, ctrl->val); in ov5647_s_ctrl()
1248 ret = ov5647_s_exposure_auto(sd, ctrl->val); in ov5647_s_ctrl()
1251 ret = ov5647_s_analogue_gain(sd, ctrl->val); in ov5647_s_ctrl()
1254 ret = ov5647_s_exposure(sd, ctrl->val); in ov5647_s_ctrl()
1258 sensor->mode->format.height + ctrl->val); in ov5647_s_ctrl()
1262 ov5647_test_pattern_val[ctrl->val]); in ov5647_s_ctrl()
1265 /* Read-only, but we adjust it based on mode. */ in ov5647_s_ctrl()
1268 /* Read-only, but we adjust it based on mode. */ in ov5647_s_ctrl()
1272 dev_info(&client->dev, in ov5647_s_ctrl()
1274 ctrl->id, ctrl->val); in ov5647_s_ctrl()
1275 return -EINVAL; in ov5647_s_ctrl()
1278 pm_runtime_put(&client->dev); in ov5647_s_ctrl()
1289 struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd); in ov5647_init_controls()
1292 v4l2_ctrl_handler_init(&sensor->ctrls, 9); in ov5647_init_controls()
1294 v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1295 V4L2_CID_AUTOGAIN, 0, 1, 1, 0); in ov5647_init_controls()
1297 v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1298 V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 0); in ov5647_init_controls()
1300 v4l2_ctrl_new_std_menu(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1304 exposure_max = sensor->mode->vts - 4; in ov5647_init_controls()
1306 sensor->exposure = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1313 v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1314 V4L2_CID_ANALOGUE_GAIN, 16, 1023, 1, 32); in ov5647_init_controls()
1317 sensor->pixel_rate = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1319 sensor->mode->pixel_rate, in ov5647_init_controls()
1320 sensor->mode->pixel_rate, 1, in ov5647_init_controls()
1321 sensor->mode->pixel_rate); in ov5647_init_controls()
1324 hblank = sensor->mode->hts - sensor->mode->format.width; in ov5647_init_controls()
1325 sensor->hblank = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1326 V4L2_CID_HBLANK, hblank, hblank, 1, in ov5647_init_controls()
1329 sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1331 OV5647_VTS_MAX - in ov5647_init_controls()
1332 sensor->mode->format.height, 1, in ov5647_init_controls()
1333 sensor->mode->vts - in ov5647_init_controls()
1334 sensor->mode->format.height); in ov5647_init_controls()
1336 v4l2_ctrl_new_std_menu_items(&sensor->ctrls, &ov5647_ctrl_ops, in ov5647_init_controls()
1338 ARRAY_SIZE(ov5647_test_pattern_menu) - 1, in ov5647_init_controls()
1341 if (sensor->ctrls.error) in ov5647_init_controls()
1344 sensor->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5647_init_controls()
1345 sensor->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5647_init_controls()
1346 sensor->sd.ctrl_handler = &sensor->ctrls; in ov5647_init_controls()
1351 dev_err(&client->dev, "%s Controls initialization failed (%d)\n", in ov5647_init_controls()
1352 __func__, sensor->ctrls.error); in ov5647_init_controls()
1353 v4l2_ctrl_handler_free(&sensor->ctrls); in ov5647_init_controls()
1355 return sensor->ctrls.error; in ov5647_init_controls()
1364 of_graph_get_endpoint_by_regs(np, 0, -1); in ov5647_parse_dt()
1368 return -EINVAL; in ov5647_parse_dt()
1374 sensor->clock_ncont = bus_cfg.bus.mipi_csi2.flags & in ov5647_parse_dt()
1382 struct device_node *np = client->dev.of_node; in ov5647_probe()
1383 struct device *dev = &client->dev; in ov5647_probe()
1391 return -ENOMEM; in ov5647_probe()
1401 sensor->xclk = devm_clk_get(dev, NULL); in ov5647_probe()
1402 if (IS_ERR(sensor->xclk)) { in ov5647_probe()
1404 return PTR_ERR(sensor->xclk); in ov5647_probe()
1407 xclk_freq = clk_get_rate(sensor->xclk); in ov5647_probe()
1410 return -EINVAL; in ov5647_probe()
1414 sensor->pwdn = devm_gpiod_get_optional(dev, "pwdn", GPIOD_OUT_HIGH); in ov5647_probe()
1415 if (IS_ERR(sensor->pwdn)) { in ov5647_probe()
1417 return -EINVAL; in ov5647_probe()
1420 mutex_init(&sensor->lock); in ov5647_probe()
1422 sensor->mode = OV5647_DEFAULT_MODE; in ov5647_probe()
1428 sd = &sensor->sd; in ov5647_probe()
1430 sd->internal_ops = &ov5647_subdev_internal_ops; in ov5647_probe()
1431 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in ov5647_probe()
1433 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in ov5647_probe()
1434 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov5647_probe()
1435 ret = media_entity_pads_init(&sd->entity, 1, &sensor->pad); in ov5647_probe()
1463 media_entity_cleanup(&sd->entity); in ov5647_probe()
1465 v4l2_ctrl_handler_free(&sensor->ctrls); in ov5647_probe()
1467 mutex_destroy(&sensor->lock); in ov5647_probe()
1477 v4l2_async_unregister_subdev(&sensor->sd); in ov5647_remove()
1478 media_entity_cleanup(&sensor->sd.entity); in ov5647_remove()
1479 v4l2_ctrl_handler_free(&sensor->ctrls); in ov5647_remove()
1481 pm_runtime_disable(&client->dev); in ov5647_remove()
1482 mutex_destroy(&sensor->lock); in ov5647_remove()
1517 MODULE_DESCRIPTION("A low-level driver for OmniVision ov5647 sensors");