Lines Matching +full:trig +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0
22 #include <media/media-entity.h>
23 #include <media/v4l2-async.h>
24 #include <media/v4l2-common.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-device.h>
27 #include <media/v4l2-fwnode.h>
28 #include <media/v4l2-mediabus.h>
29 #include <media/v4l2-subdev.h>
403 * AM19 : 3617 <- 0xC0
459 {0x3031, 0x0a}, /* MIPI 10-bit mode */
729 * AM19 : 3617 <- 0xC0
807 * AM19 : 3617 <- 0xC0
864 {0x3031, 0x0a}, /* MIPI 10-bit mode */
1020 {0x4000, 0xf1}, /* out_range/format_chg/gain/exp_chg trig enable */
1237 /* ----------------------------------------------------------------------------
1243 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_write()
1253 put_unaligned_be32(val << (8 * (4 - len)), buf + 2); in ov8858_write()
1257 ret = ret < 0 ? ret : -EIO; in ov8858_write()
1261 dev_err(&client->dev, in ov8858_write()
1284 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_read()
1295 msgs[0].addr = client->addr; in ov8858_read()
1301 msgs[1].addr = client->addr; in ov8858_read()
1304 msgs[1].buf = &data_be_p[4 - len]; in ov8858_read()
1306 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in ov8858_read()
1308 ret = ret < 0 ? ret : -EIO; in ov8858_read()
1309 dev_err(&client->dev, in ov8858_read()
1319 /* ----------------------------------------------------------------------------
1331 ret = ov8858_write_array(ov8858, ov8858->global_regs); in ov8858_start_stream()
1337 width, height, format->width, in ov8858_start_stream()
1338 format->height); in ov8858_start_stream()
1340 reg_list = ov8858->num_lanes == 4 in ov8858_start_stream()
1341 ? mode->reg_modes.mode_4lanes in ov8858_start_stream()
1342 : mode->reg_modes.mode_2lanes; in ov8858_start_stream()
1351 ret = __v4l2_ctrl_handler_setup(&ov8858->ctrl_handler); in ov8858_start_stream()
1382 ret = pm_runtime_resume_and_get(&client->dev); in ov8858_s_stream()
1388 dev_err(&client->dev, "Failed to start streaming\n"); in ov8858_s_stream()
1389 pm_runtime_put_sync(&client->dev); in ov8858_s_stream()
1394 pm_runtime_mark_last_busy(&client->dev); in ov8858_s_stream()
1395 pm_runtime_put_autosuspend(&client->dev); in ov8858_s_stream()
1408 /* ----------------------------------------------------------------------------
1421 width, height, fmt->format.width, in ov8858_set_fmt()
1422 fmt->format.height); in ov8858_set_fmt()
1424 fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; in ov8858_set_fmt()
1425 fmt->format.width = mode->width; in ov8858_set_fmt()
1426 fmt->format.height = mode->height; in ov8858_set_fmt()
1427 fmt->format.field = V4L2_FIELD_NONE; in ov8858_set_fmt()
1430 *v4l2_subdev_state_get_format(state, 0) = fmt->format; in ov8858_set_fmt()
1432 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) in ov8858_set_fmt()
1436 h_blank = mode->hts_def - mode->width; in ov8858_set_fmt()
1437 __v4l2_ctrl_modify_range(ov8858->hblank, h_blank, h_blank, 1, in ov8858_set_fmt()
1440 vblank_def = mode->vts_def - mode->height; in ov8858_set_fmt()
1441 __v4l2_ctrl_modify_range(ov8858->vblank, vblank_def, in ov8858_set_fmt()
1442 OV8858_VTS_MAX - mode->height, 1, in ov8858_set_fmt()
1452 if (fse->index >= ARRAY_SIZE(ov8858_modes)) in ov8858_enum_frame_sizes()
1453 return -EINVAL; in ov8858_enum_frame_sizes()
1455 if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) in ov8858_enum_frame_sizes()
1456 return -EINVAL; in ov8858_enum_frame_sizes()
1458 fse->min_width = ov8858_modes[fse->index].width; in ov8858_enum_frame_sizes()
1459 fse->max_width = ov8858_modes[fse->index].width; in ov8858_enum_frame_sizes()
1460 fse->max_height = ov8858_modes[fse->index].height; in ov8858_enum_frame_sizes()
1461 fse->min_height = ov8858_modes[fse->index].height; in ov8858_enum_frame_sizes()
1470 if (code->index != 0) in ov8858_enum_mbus_code()
1471 return -EINVAL; in ov8858_enum_mbus_code()
1473 code->code = MEDIA_BUS_FMT_SBGGR10_1X10; in ov8858_enum_mbus_code()
1485 .width = def_mode->width, in ov8858_init_state()
1486 .height = def_mode->height, in ov8858_init_state()
1511 /* ----------------------------------------------------------------------------
1520 val = (pattern - 1) | OV8858_TEST_PATTERN_ENABLE; in ov8858_enable_test_pattern()
1529 struct ov8858 *ov8858 = container_of(ctrl->handler, in ov8858_set_ctrl()
1532 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_set_ctrl()
1542 * - by the core when s_ctrl is called int the VIDIOC_S_CTRL call path in ov8858_set_ctrl()
1543 * - by the driver when s_ctrl is called in the s_stream(1) call path in ov8858_set_ctrl()
1545 state = v4l2_subdev_get_locked_active_state(&ov8858->subdev); in ov8858_set_ctrl()
1549 switch (ctrl->id) { in ov8858_set_ctrl()
1552 max_exp = format->height + ctrl->val - OV8858_EXPOSURE_MARGIN; in ov8858_set_ctrl()
1553 __v4l2_ctrl_modify_range(ov8858->exposure, in ov8858_set_ctrl()
1554 ov8858->exposure->minimum, max_exp, in ov8858_set_ctrl()
1555 ov8858->exposure->step, in ov8858_set_ctrl()
1556 ov8858->exposure->default_value); in ov8858_set_ctrl()
1560 if (!pm_runtime_get_if_in_use(&client->dev)) in ov8858_set_ctrl()
1563 switch (ctrl->id) { in ov8858_set_ctrl()
1567 ctrl->val << 4, NULL); in ov8858_set_ctrl()
1571 ctrl->val, NULL); in ov8858_set_ctrl()
1580 digi_gain = (ctrl->val & OV8858_LONG_DIGIGAIN_L_MASK) in ov8858_set_ctrl()
1581 | ((ctrl->val & OV8858_LONG_DIGIGAIN_H_MASK) << in ov8858_set_ctrl()
1588 ctrl->val + format->height, NULL); in ov8858_set_ctrl()
1591 ret = ov8858_enable_test_pattern(ov8858, ctrl->val); in ov8858_set_ctrl()
1594 ret = -EINVAL; in ov8858_set_ctrl()
1595 dev_warn(&client->dev, "%s Unhandled id: 0x%x\n", in ov8858_set_ctrl()
1596 __func__, ctrl->id); in ov8858_set_ctrl()
1600 pm_runtime_put(&client->dev); in ov8858_set_ctrl()
1609 /* ----------------------------------------------------------------------------
1615 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_power_on()
1616 struct device *dev = &client->dev; in ov8858_power_on()
1620 if (clk_get_rate(ov8858->xvclk) != OV8858_XVCLK_FREQ) in ov8858_power_on()
1623 ret = clk_prepare_enable(ov8858->xvclk); in ov8858_power_on()
1630 ov8858->supplies); in ov8858_power_on()
1638 * transaction, but a double sleep between the release of gpios in ov8858_power_on()
1643 gpiod_set_value_cansleep(ov8858->reset_gpio, 0); in ov8858_power_on()
1645 gpiod_set_value_cansleep(ov8858->pwdn_gpio, 0); in ov8858_power_on()
1651 clk_disable_unprepare(ov8858->xvclk); in ov8858_power_on()
1658 gpiod_set_value_cansleep(ov8858->pwdn_gpio, 1); in ov8858_power_off()
1659 clk_disable_unprepare(ov8858->xvclk); in ov8858_power_off()
1660 gpiod_set_value_cansleep(ov8858->reset_gpio, 1); in ov8858_power_off()
1663 ov8858->supplies); in ov8858_power_off()
1691 /* ----------------------------------------------------------------------------
1697 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_init_ctrls()
1698 struct v4l2_ctrl_handler *handler = &ov8858->ctrl_handler; in ov8858_init_ctrls()
1714 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8858_init_ctrls()
1717 pixel_rate = OV8858_LINK_FREQ * 2 * ov8858->num_lanes / 10; in ov8858_init_ctrls()
1721 h_blank = mode->hts_def - mode->width; in ov8858_init_ctrls()
1722 ov8858->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in ov8858_init_ctrls()
1724 if (ov8858->hblank) in ov8858_init_ctrls()
1725 ov8858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8858_init_ctrls()
1727 vblank_def = mode->vts_def - mode->height; in ov8858_init_ctrls()
1728 ov8858->vblank = v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops, in ov8858_init_ctrls()
1730 OV8858_VTS_MAX - mode->height, in ov8858_init_ctrls()
1733 exposure_max = mode->vts_def - OV8858_EXPOSURE_MARGIN; in ov8858_init_ctrls()
1734 ov8858->exposure = v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops, in ov8858_init_ctrls()
1738 mode->exp_def); in ov8858_init_ctrls()
1751 ARRAY_SIZE(ov8858_test_pattern_menu) - 1, in ov8858_init_ctrls()
1754 if (handler->error) { in ov8858_init_ctrls()
1755 ret = handler->error; in ov8858_init_ctrls()
1759 ret = v4l2_fwnode_device_parse(&client->dev, &props); in ov8858_init_ctrls()
1768 ov8858->subdev.ctrl_handler = handler; in ov8858_init_ctrls()
1773 dev_err(&client->dev, "Failed to init controls: %d\n", ret); in ov8858_init_ctrls()
1781 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_check_sensor_id()
1790 dev_err(&client->dev, "Unexpected sensor id 0x%x\n", id); in ov8858_check_sensor_id()
1791 return -ENODEV; in ov8858_check_sensor_id()
1798 dev_info(&client->dev, "Detected OV8858 sensor, revision 0x%x\n", id); in ov8858_check_sensor_id()
1802 ov8858->global_regs = ov8858->num_lanes == 4 in ov8858_check_sensor_id()
1805 } else if (ov8858->num_lanes == 2) { in ov8858_check_sensor_id()
1810 ov8858->global_regs = ov8858_global_regs_r1a; in ov8858_check_sensor_id()
1811 dev_warn(&client->dev, "R1A may not work well!\n"); in ov8858_check_sensor_id()
1813 dev_err(&client->dev, in ov8858_check_sensor_id()
1815 return -EINVAL; in ov8858_check_sensor_id()
1823 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_configure_regulators()
1827 ov8858->supplies[i].supply = ov8858_supply_names[i]; in ov8858_configure_regulators()
1829 return devm_regulator_bulk_get(&client->dev, in ov8858_configure_regulators()
1831 ov8858->supplies); in ov8858_configure_regulators()
1837 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_parse_of()
1838 struct device *dev = &client->dev; in ov8858_parse_of()
1845 return -EINVAL; in ov8858_parse_of()
1855 ov8858->num_lanes = vep.bus.mipi_csi2.num_data_lanes; in ov8858_parse_of()
1856 switch (ov8858->num_lanes) { in ov8858_parse_of()
1862 ov8858->num_lanes); in ov8858_parse_of()
1863 return -EINVAL; in ov8858_parse_of()
1871 struct device *dev = &client->dev; in ov8858_probe()
1878 return -ENOMEM; in ov8858_probe()
1880 ov8858->xvclk = devm_clk_get(dev, "xvclk"); in ov8858_probe()
1881 if (IS_ERR(ov8858->xvclk)) in ov8858_probe()
1882 return dev_err_probe(dev, PTR_ERR(ov8858->xvclk), in ov8858_probe()
1885 ov8858->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov8858_probe()
1887 if (IS_ERR(ov8858->reset_gpio)) in ov8858_probe()
1888 return dev_err_probe(dev, PTR_ERR(ov8858->reset_gpio), in ov8858_probe()
1891 ov8858->pwdn_gpio = devm_gpiod_get_optional(dev, "powerdown", in ov8858_probe()
1893 if (IS_ERR(ov8858->pwdn_gpio)) in ov8858_probe()
1894 return dev_err_probe(dev, PTR_ERR(ov8858->pwdn_gpio), in ov8858_probe()
1897 v4l2_i2c_subdev_init(&ov8858->subdev, client, &ov8858_subdev_ops); in ov8858_probe()
1898 ov8858->subdev.internal_ops = &ov8858_internal_ops; in ov8858_probe()
1912 sd = &ov8858->subdev; in ov8858_probe()
1913 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov8858_probe()
1914 ov8858->pad.flags = MEDIA_PAD_FL_SOURCE; in ov8858_probe()
1915 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov8858_probe()
1916 ret = media_entity_pads_init(&sd->entity, 1, &ov8858->pad); in ov8858_probe()
1920 sd->state_lock = ov8858->ctrl_handler.lock; in ov8858_probe()
1923 dev_err(&client->dev, "Subdev initialization error %d\n", ret); in ov8858_probe()
1958 media_entity_cleanup(&sd->entity); in ov8858_probe()
1960 v4l2_ctrl_handler_free(&ov8858->ctrl_handler); in ov8858_probe()
1971 media_entity_cleanup(&sd->entity); in ov8858_remove()
1972 v4l2_ctrl_handler_free(&ov8858->ctrl_handler); in ov8858_remove()
1974 pm_runtime_disable(&client->dev); in ov8858_remove()
1975 if (!pm_runtime_status_suspended(&client->dev)) in ov8858_remove()
1977 pm_runtime_set_suspended(&client->dev); in ov8858_remove()