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-event.h>
28 #include <media/v4l2-fwnode.h>
29 #include <media/v4l2-mediabus.h>
30 #include <media/v4l2-subdev.h>
404 * AM19 : 3617 <- 0xC0
460 {0x3031, 0x0a}, /* MIPI 10-bit mode */
730 * AM19 : 3617 <- 0xC0
808 * AM19 : 3617 <- 0xC0
865 {0x3031, 0x0a}, /* MIPI 10-bit mode */
1021 {0x4000, 0xf1}, /* out_range/format_chg/gain/exp_chg trig enable */
1238 /* ----------------------------------------------------------------------------
1244 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_write()
1254 put_unaligned_be32(val << (8 * (4 - len)), buf + 2); in ov8858_write()
1258 ret = ret < 0 ? ret : -EIO; in ov8858_write()
1262 dev_err(&client->dev, in ov8858_write()
1285 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_read()
1296 msgs[0].addr = client->addr; in ov8858_read()
1302 msgs[1].addr = client->addr; in ov8858_read()
1305 msgs[1].buf = &data_be_p[4 - len]; in ov8858_read()
1307 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in ov8858_read()
1309 ret = ret < 0 ? ret : -EIO; in ov8858_read()
1310 dev_err(&client->dev, in ov8858_read()
1320 /* ----------------------------------------------------------------------------
1332 ret = ov8858_write_array(ov8858, ov8858->global_regs); in ov8858_start_stream()
1336 format = v4l2_subdev_get_pad_format(&ov8858->subdev, state, 0); in ov8858_start_stream()
1338 width, height, format->width, in ov8858_start_stream()
1339 format->height); in ov8858_start_stream()
1341 reg_list = ov8858->num_lanes == 4 in ov8858_start_stream()
1342 ? mode->reg_modes.mode_4lanes in ov8858_start_stream()
1343 : mode->reg_modes.mode_2lanes; in ov8858_start_stream()
1352 ret = __v4l2_ctrl_handler_setup(&ov8858->ctrl_handler); in ov8858_start_stream()
1383 ret = pm_runtime_resume_and_get(&client->dev); in ov8858_s_stream()
1389 dev_err(&client->dev, "Failed to start streaming\n"); in ov8858_s_stream()
1390 pm_runtime_put_sync(&client->dev); in ov8858_s_stream()
1395 pm_runtime_mark_last_busy(&client->dev); in ov8858_s_stream()
1396 pm_runtime_put_autosuspend(&client->dev); in ov8858_s_stream()
1409 /* ----------------------------------------------------------------------------
1422 width, height, fmt->format.width, in ov8858_set_fmt()
1423 fmt->format.height); in ov8858_set_fmt()
1425 fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; in ov8858_set_fmt()
1426 fmt->format.width = mode->width; in ov8858_set_fmt()
1427 fmt->format.height = mode->height; in ov8858_set_fmt()
1428 fmt->format.field = V4L2_FIELD_NONE; in ov8858_set_fmt()
1431 *v4l2_subdev_get_pad_format(sd, state, 0) = fmt->format; in ov8858_set_fmt()
1433 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) in ov8858_set_fmt()
1437 h_blank = mode->hts_def - mode->width; in ov8858_set_fmt()
1438 __v4l2_ctrl_modify_range(ov8858->hblank, h_blank, h_blank, 1, in ov8858_set_fmt()
1441 vblank_def = mode->vts_def - mode->height; in ov8858_set_fmt()
1442 __v4l2_ctrl_modify_range(ov8858->vblank, vblank_def, in ov8858_set_fmt()
1443 OV8858_VTS_MAX - mode->height, 1, in ov8858_set_fmt()
1453 if (fse->index >= ARRAY_SIZE(ov8858_modes)) in ov8858_enum_frame_sizes()
1454 return -EINVAL; in ov8858_enum_frame_sizes()
1456 if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) in ov8858_enum_frame_sizes()
1457 return -EINVAL; in ov8858_enum_frame_sizes()
1459 fse->min_width = ov8858_modes[fse->index].width; in ov8858_enum_frame_sizes()
1460 fse->max_width = ov8858_modes[fse->index].width; in ov8858_enum_frame_sizes()
1461 fse->max_height = ov8858_modes[fse->index].height; in ov8858_enum_frame_sizes()
1462 fse->min_height = ov8858_modes[fse->index].height; in ov8858_enum_frame_sizes()
1471 if (code->index != 0) in ov8858_enum_mbus_code()
1472 return -EINVAL; in ov8858_enum_mbus_code()
1474 code->code = MEDIA_BUS_FMT_SBGGR10_1X10; in ov8858_enum_mbus_code()
1486 .width = def_mode->width, in ov8858_init_cfg()
1487 .height = def_mode->height, in ov8858_init_cfg()
1515 /* ----------------------------------------------------------------------------
1524 val = (pattern - 1) | OV8858_TEST_PATTERN_ENABLE; in ov8858_enable_test_pattern()
1533 struct ov8858 *ov8858 = container_of(ctrl->handler, in ov8858_set_ctrl()
1536 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_set_ctrl()
1546 * - by the core when s_ctrl is called int the VIDIOC_S_CTRL call path in ov8858_set_ctrl()
1547 * - by the driver when s_ctrl is called in the s_stream(1) call path in ov8858_set_ctrl()
1549 state = v4l2_subdev_get_locked_active_state(&ov8858->subdev); in ov8858_set_ctrl()
1550 format = v4l2_subdev_get_pad_format(&ov8858->subdev, state, 0); in ov8858_set_ctrl()
1553 switch (ctrl->id) { in ov8858_set_ctrl()
1556 max_exp = format->height + ctrl->val - OV8858_EXPOSURE_MARGIN; in ov8858_set_ctrl()
1557 __v4l2_ctrl_modify_range(ov8858->exposure, in ov8858_set_ctrl()
1558 ov8858->exposure->minimum, max_exp, in ov8858_set_ctrl()
1559 ov8858->exposure->step, in ov8858_set_ctrl()
1560 ov8858->exposure->default_value); in ov8858_set_ctrl()
1564 if (!pm_runtime_get_if_in_use(&client->dev)) in ov8858_set_ctrl()
1567 switch (ctrl->id) { in ov8858_set_ctrl()
1571 ctrl->val << 4, NULL); in ov8858_set_ctrl()
1575 ctrl->val, NULL); in ov8858_set_ctrl()
1584 digi_gain = (ctrl->val & OV8858_LONG_DIGIGAIN_L_MASK) in ov8858_set_ctrl()
1585 | ((ctrl->val & OV8858_LONG_DIGIGAIN_H_MASK) << in ov8858_set_ctrl()
1592 ctrl->val + format->height, NULL); in ov8858_set_ctrl()
1595 ret = ov8858_enable_test_pattern(ov8858, ctrl->val); in ov8858_set_ctrl()
1598 ret = -EINVAL; in ov8858_set_ctrl()
1599 dev_warn(&client->dev, "%s Unhandled id: 0x%x\n", in ov8858_set_ctrl()
1600 __func__, ctrl->id); in ov8858_set_ctrl()
1604 pm_runtime_put(&client->dev); in ov8858_set_ctrl()
1613 /* ----------------------------------------------------------------------------
1619 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_power_on()
1620 struct device *dev = &client->dev; in ov8858_power_on()
1624 if (clk_get_rate(ov8858->xvclk) != OV8858_XVCLK_FREQ) in ov8858_power_on()
1627 ret = clk_prepare_enable(ov8858->xvclk); in ov8858_power_on()
1634 ov8858->supplies); in ov8858_power_on()
1642 * transaction, but a double sleep between the release of gpios in ov8858_power_on()
1647 gpiod_set_value_cansleep(ov8858->reset_gpio, 0); in ov8858_power_on()
1649 gpiod_set_value_cansleep(ov8858->pwdn_gpio, 0); in ov8858_power_on()
1655 clk_disable_unprepare(ov8858->xvclk); in ov8858_power_on()
1662 gpiod_set_value_cansleep(ov8858->pwdn_gpio, 1); in ov8858_power_off()
1663 clk_disable_unprepare(ov8858->xvclk); in ov8858_power_off()
1664 gpiod_set_value_cansleep(ov8858->reset_gpio, 1); in ov8858_power_off()
1667 ov8858->supplies); in ov8858_power_off()
1695 /* ----------------------------------------------------------------------------
1701 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_init_ctrls()
1702 struct v4l2_ctrl_handler *handler = &ov8858->ctrl_handler; in ov8858_init_ctrls()
1718 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8858_init_ctrls()
1721 pixel_rate = OV8858_LINK_FREQ * 2 * ov8858->num_lanes / 10; in ov8858_init_ctrls()
1725 h_blank = mode->hts_def - mode->width; in ov8858_init_ctrls()
1726 ov8858->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in ov8858_init_ctrls()
1728 if (ov8858->hblank) in ov8858_init_ctrls()
1729 ov8858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8858_init_ctrls()
1731 vblank_def = mode->vts_def - mode->height; in ov8858_init_ctrls()
1732 ov8858->vblank = v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops, in ov8858_init_ctrls()
1734 OV8858_VTS_MAX - mode->height, in ov8858_init_ctrls()
1737 exposure_max = mode->vts_def - OV8858_EXPOSURE_MARGIN; in ov8858_init_ctrls()
1738 ov8858->exposure = v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops, in ov8858_init_ctrls()
1742 mode->exp_def); in ov8858_init_ctrls()
1755 ARRAY_SIZE(ov8858_test_pattern_menu) - 1, in ov8858_init_ctrls()
1758 if (handler->error) { in ov8858_init_ctrls()
1759 ret = handler->error; in ov8858_init_ctrls()
1763 ret = v4l2_fwnode_device_parse(&client->dev, &props); in ov8858_init_ctrls()
1772 ov8858->subdev.ctrl_handler = handler; in ov8858_init_ctrls()
1777 dev_err(&client->dev, "Failed to init controls: %d\n", ret); in ov8858_init_ctrls()
1785 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_check_sensor_id()
1794 dev_err(&client->dev, "Unexpected sensor id 0x%x\n", id); in ov8858_check_sensor_id()
1795 return -ENODEV; in ov8858_check_sensor_id()
1802 dev_info(&client->dev, "Detected OV8858 sensor, revision 0x%x\n", id); in ov8858_check_sensor_id()
1806 ov8858->global_regs = ov8858->num_lanes == 4 in ov8858_check_sensor_id()
1809 } else if (ov8858->num_lanes == 2) { in ov8858_check_sensor_id()
1814 ov8858->global_regs = ov8858_global_regs_r1a; in ov8858_check_sensor_id()
1815 dev_warn(&client->dev, "R1A may not work well!\n"); in ov8858_check_sensor_id()
1817 dev_err(&client->dev, in ov8858_check_sensor_id()
1819 return -EINVAL; in ov8858_check_sensor_id()
1827 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_configure_regulators()
1831 ov8858->supplies[i].supply = ov8858_supply_names[i]; in ov8858_configure_regulators()
1833 return devm_regulator_bulk_get(&client->dev, in ov8858_configure_regulators()
1835 ov8858->supplies); in ov8858_configure_regulators()
1841 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev); in ov8858_parse_of()
1842 struct device *dev = &client->dev; in ov8858_parse_of()
1849 return -EINVAL; in ov8858_parse_of()
1859 ov8858->num_lanes = vep.bus.mipi_csi2.num_data_lanes; in ov8858_parse_of()
1860 switch (ov8858->num_lanes) { in ov8858_parse_of()
1866 ov8858->num_lanes); in ov8858_parse_of()
1867 return -EINVAL; in ov8858_parse_of()
1875 struct device *dev = &client->dev; in ov8858_probe()
1882 return -ENOMEM; in ov8858_probe()
1884 ov8858->xvclk = devm_clk_get(dev, "xvclk"); in ov8858_probe()
1885 if (IS_ERR(ov8858->xvclk)) in ov8858_probe()
1886 return dev_err_probe(dev, PTR_ERR(ov8858->xvclk), in ov8858_probe()
1889 ov8858->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov8858_probe()
1891 if (IS_ERR(ov8858->reset_gpio)) in ov8858_probe()
1892 return dev_err_probe(dev, PTR_ERR(ov8858->reset_gpio), in ov8858_probe()
1895 ov8858->pwdn_gpio = devm_gpiod_get_optional(dev, "powerdown", in ov8858_probe()
1897 if (IS_ERR(ov8858->pwdn_gpio)) in ov8858_probe()
1898 return dev_err_probe(dev, PTR_ERR(ov8858->pwdn_gpio), in ov8858_probe()
1901 v4l2_i2c_subdev_init(&ov8858->subdev, client, &ov8858_subdev_ops); in ov8858_probe()
1915 sd = &ov8858->subdev; in ov8858_probe()
1916 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in ov8858_probe()
1917 ov8858->pad.flags = MEDIA_PAD_FL_SOURCE; in ov8858_probe()
1918 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov8858_probe()
1919 ret = media_entity_pads_init(&sd->entity, 1, &ov8858->pad); in ov8858_probe()
1923 sd->state_lock = ov8858->ctrl_handler.lock; in ov8858_probe()
1926 dev_err(&client->dev, "Subdev initialization error %d\n", ret); in ov8858_probe()
1961 media_entity_cleanup(&sd->entity); in ov8858_probe()
1963 v4l2_ctrl_handler_free(&ov8858->ctrl_handler); in ov8858_probe()
1974 media_entity_cleanup(&sd->entity); in ov8858_remove()
1975 v4l2_ctrl_handler_free(&ov8858->ctrl_handler); in ov8858_remove()
1977 pm_runtime_disable(&client->dev); in ov8858_remove()
1978 if (!pm_runtime_status_suspended(&client->dev)) in ov8858_remove()
1980 pm_runtime_set_suspended(&client->dev); in ov8858_remove()