Lines Matching +full:llp +full:- +full:based

1 // SPDX-License-Identifier: GPL-2.0
9 #include <media/v4l2-ctrls.h>
10 #include <media/v4l2-device.h>
11 #include <media/v4l2-event.h>
12 #include <media/v4l2-fwnode.h>
34 * +-----------------+------------------+
36 * +-----------------+------------------+
38 * --------------------------------------
94 /* V-timing */
98 /* H-timing */
99 u32 llp; member
110 s64 *link_freqs; /* CSI-2 link frequencies */
132 s64 link_def_freq; /* CSI-2 link default frequency */
1671 .llp = 3968,
1683 .llp = 3968,
1695 .llp = 3968,
1707 .llp = 3968,
1719 .llp = 2500,
1731 .llp = 2500,
1743 .llp = 2500,
1755 .llp = 2500,
1769 /* Get bayer order based on flip setting. */
1782 lockdep_assert_held(&imx319->mutex); in imx319_get_format_code()
1783 code = codes[imx319->vflip->val][imx319->hflip->val]; in imx319_get_format_code()
1791 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_read_reg()
1798 return -EINVAL; in imx319_read_reg()
1802 msgs[0].addr = client->addr; in imx319_read_reg()
1808 msgs[1].addr = client->addr; in imx319_read_reg()
1811 msgs[1].buf = &data_buf[4 - len]; in imx319_read_reg()
1813 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in imx319_read_reg()
1815 return -EIO; in imx319_read_reg()
1825 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_write_reg()
1829 return -EINVAL; in imx319_write_reg()
1832 put_unaligned_be32(val << (8 * (4 - len)), buf + 2); in imx319_write_reg()
1834 return -EIO; in imx319_write_reg()
1843 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_write_regs()
1850 dev_err_ratelimited(&client->dev, in imx319_write_regs()
1860 /* Open sub-device */
1865 v4l2_subdev_get_try_format(sd, fh->state, 0); in imx319_open()
1867 mutex_lock(&imx319->mutex); in imx319_open()
1870 try_fmt->width = imx319->cur_mode->width; in imx319_open()
1871 try_fmt->height = imx319->cur_mode->height; in imx319_open()
1872 try_fmt->code = imx319_get_format_code(imx319); in imx319_open()
1873 try_fmt->field = V4L2_FIELD_NONE; in imx319_open()
1875 mutex_unlock(&imx319->mutex); in imx319_open()
1882 struct imx319 *imx319 = container_of(ctrl->handler, in imx319_set_ctrl()
1884 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_set_ctrl()
1889 switch (ctrl->id) { in imx319_set_ctrl()
1892 max = imx319->cur_mode->height + ctrl->val - 18; in imx319_set_ctrl()
1893 __v4l2_ctrl_modify_range(imx319->exposure, in imx319_set_ctrl()
1894 imx319->exposure->minimum, in imx319_set_ctrl()
1895 max, imx319->exposure->step, max); in imx319_set_ctrl()
1903 if (!pm_runtime_get_if_in_use(&client->dev)) in imx319_set_ctrl()
1906 switch (ctrl->id) { in imx319_set_ctrl()
1908 /* Analog gain = 1024/(1024 - ctrl->val) times */ in imx319_set_ctrl()
1910 ctrl->val); in imx319_set_ctrl()
1914 ctrl->val); in imx319_set_ctrl()
1918 ctrl->val); in imx319_set_ctrl()
1923 imx319->cur_mode->height + ctrl->val); in imx319_set_ctrl()
1927 2, ctrl->val); in imx319_set_ctrl()
1932 imx319->hflip->val | in imx319_set_ctrl()
1933 imx319->vflip->val << 1); in imx319_set_ctrl()
1936 ret = -EINVAL; in imx319_set_ctrl()
1937 dev_info(&client->dev, "ctrl(id:0x%x,val:0x%x) is not handled", in imx319_set_ctrl()
1938 ctrl->id, ctrl->val); in imx319_set_ctrl()
1942 pm_runtime_put(&client->dev); in imx319_set_ctrl()
1957 if (code->index > 0) in imx319_enum_mbus_code()
1958 return -EINVAL; in imx319_enum_mbus_code()
1960 mutex_lock(&imx319->mutex); in imx319_enum_mbus_code()
1961 code->code = imx319_get_format_code(imx319); in imx319_enum_mbus_code()
1962 mutex_unlock(&imx319->mutex); in imx319_enum_mbus_code()
1973 if (fse->index >= ARRAY_SIZE(supported_modes)) in imx319_enum_frame_size()
1974 return -EINVAL; in imx319_enum_frame_size()
1976 mutex_lock(&imx319->mutex); in imx319_enum_frame_size()
1977 if (fse->code != imx319_get_format_code(imx319)) { in imx319_enum_frame_size()
1978 mutex_unlock(&imx319->mutex); in imx319_enum_frame_size()
1979 return -EINVAL; in imx319_enum_frame_size()
1981 mutex_unlock(&imx319->mutex); in imx319_enum_frame_size()
1983 fse->min_width = supported_modes[fse->index].width; in imx319_enum_frame_size()
1984 fse->max_width = fse->min_width; in imx319_enum_frame_size()
1985 fse->min_height = supported_modes[fse->index].height; in imx319_enum_frame_size()
1986 fse->max_height = fse->min_height; in imx319_enum_frame_size()
1995 fmt->format.width = mode->width; in imx319_update_pad_format()
1996 fmt->format.height = mode->height; in imx319_update_pad_format()
1997 fmt->format.code = imx319_get_format_code(imx319); in imx319_update_pad_format()
1998 fmt->format.field = V4L2_FIELD_NONE; in imx319_update_pad_format()
2006 struct v4l2_subdev *sd = &imx319->sd; in imx319_do_get_pad_format()
2008 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in imx319_do_get_pad_format()
2009 framefmt = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); in imx319_do_get_pad_format()
2010 fmt->format = *framefmt; in imx319_do_get_pad_format()
2012 imx319_update_pad_format(imx319, imx319->cur_mode, fmt); in imx319_do_get_pad_format()
2025 mutex_lock(&imx319->mutex); in imx319_get_pad_format()
2027 mutex_unlock(&imx319->mutex); in imx319_get_pad_format()
2046 mutex_lock(&imx319->mutex); in imx319_set_pad_format()
2052 fmt->format.code = imx319_get_format_code(imx319); in imx319_set_pad_format()
2057 fmt->format.width, fmt->format.height); in imx319_set_pad_format()
2059 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in imx319_set_pad_format()
2060 framefmt = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); in imx319_set_pad_format()
2061 *framefmt = fmt->format; in imx319_set_pad_format()
2063 imx319->cur_mode = mode; in imx319_set_pad_format()
2064 pixel_rate = imx319->link_def_freq * 2 * 4; in imx319_set_pad_format()
2066 __v4l2_ctrl_s_ctrl_int64(imx319->pixel_rate, pixel_rate); in imx319_set_pad_format()
2068 height = imx319->cur_mode->height; in imx319_set_pad_format()
2069 vblank_def = imx319->cur_mode->fll_def - height; in imx319_set_pad_format()
2070 vblank_min = imx319->cur_mode->fll_min - height; in imx319_set_pad_format()
2071 height = IMX319_FLL_MAX - height; in imx319_set_pad_format()
2072 __v4l2_ctrl_modify_range(imx319->vblank, vblank_min, height, 1, in imx319_set_pad_format()
2074 __v4l2_ctrl_s_ctrl(imx319->vblank, vblank_def); in imx319_set_pad_format()
2075 h_blank = mode->llp - imx319->cur_mode->width; in imx319_set_pad_format()
2080 __v4l2_ctrl_modify_range(imx319->hblank, h_blank, in imx319_set_pad_format()
2084 mutex_unlock(&imx319->mutex); in imx319_set_pad_format()
2092 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_identify_module()
2096 if (imx319->identified) in imx319_identify_module()
2104 dev_err(&client->dev, "chip id mismatch: %x!=%x", in imx319_identify_module()
2106 return -EIO; in imx319_identify_module()
2109 imx319->identified = true; in imx319_identify_module()
2117 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_start_streaming()
2127 ret = imx319_write_regs(imx319, reg_list->regs, reg_list->num_of_regs); in imx319_start_streaming()
2129 dev_err(&client->dev, "failed to set global settings"); in imx319_start_streaming()
2134 reg_list = &imx319->cur_mode->reg_list; in imx319_start_streaming()
2135 ret = imx319_write_regs(imx319, reg_list->regs, reg_list->num_of_regs); in imx319_start_streaming()
2137 dev_err(&client->dev, "failed to set mode"); in imx319_start_streaming()
2147 ret = __v4l2_ctrl_handler_setup(imx319->sd.ctrl_handler); in imx319_start_streaming()
2168 mutex_lock(&imx319->mutex); in imx319_set_stream()
2169 if (imx319->streaming == enable) { in imx319_set_stream()
2170 mutex_unlock(&imx319->mutex); in imx319_set_stream()
2175 ret = pm_runtime_resume_and_get(&client->dev); in imx319_set_stream()
2188 pm_runtime_put(&client->dev); in imx319_set_stream()
2191 imx319->streaming = enable; in imx319_set_stream()
2194 __v4l2_ctrl_grab(imx319->vflip, enable); in imx319_set_stream()
2195 __v4l2_ctrl_grab(imx319->hflip, enable); in imx319_set_stream()
2197 mutex_unlock(&imx319->mutex); in imx319_set_stream()
2202 pm_runtime_put(&client->dev); in imx319_set_stream()
2204 mutex_unlock(&imx319->mutex); in imx319_set_stream()
2214 if (imx319->streaming) in imx319_suspend()
2226 if (imx319->streaming) { in imx319_resume()
2236 imx319->streaming = 0; in imx319_resume()
2273 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_init_controls()
2284 ctrl_hdlr = &imx319->ctrl_handler; in imx319_init_controls()
2289 ctrl_hdlr->lock = &imx319->mutex; in imx319_init_controls()
2290 max = ARRAY_SIZE(link_freq_menu_items) - 1; in imx319_init_controls()
2291 imx319->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2294 if (imx319->link_freq) in imx319_init_controls()
2295 imx319->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx319_init_controls()
2298 pixel_rate = imx319->link_def_freq * 2 * 4; in imx319_init_controls()
2301 imx319->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2305 /* Initial vblank/hblank/exposure parameters based on current mode */ in imx319_init_controls()
2306 mode = imx319->cur_mode; in imx319_init_controls()
2307 vblank_def = mode->fll_def - mode->height; in imx319_init_controls()
2308 vblank_min = mode->fll_min - mode->height; in imx319_init_controls()
2309 imx319->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2311 IMX319_FLL_MAX - mode->height, in imx319_init_controls()
2314 hblank = mode->llp - mode->width; in imx319_init_controls()
2315 imx319->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2318 if (imx319->hblank) in imx319_init_controls()
2319 imx319->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx319_init_controls()
2322 exposure_max = mode->fll_def - 18; in imx319_init_controls()
2323 imx319->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2329 imx319->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2331 if (imx319->hflip) in imx319_init_controls()
2332 imx319->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx319_init_controls()
2333 imx319->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2335 if (imx319->vflip) in imx319_init_controls()
2336 imx319->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx319_init_controls()
2349 ARRAY_SIZE(imx319_test_pattern_menu) - 1, in imx319_init_controls()
2351 if (ctrl_hdlr->error) { in imx319_init_controls()
2352 ret = ctrl_hdlr->error; in imx319_init_controls()
2353 dev_err(&client->dev, "control init failed: %d", ret); in imx319_init_controls()
2357 imx319->sd.ctrl_handler = ctrl_hdlr; in imx319_init_controls()
2393 ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency", in imx319_get_hwcfg()
2394 &cfg->ext_clk); in imx319_get_hwcfg()
2400 dev_dbg(dev, "ext clk: %d", cfg->ext_clk); in imx319_get_hwcfg()
2401 if (cfg->ext_clk != IMX319_EXT_CLK) { in imx319_get_hwcfg()
2403 cfg->ext_clk); in imx319_get_hwcfg()
2413 cfg->nr_of_link_freqs = bus_cfg.nr_of_link_frequencies; in imx319_get_hwcfg()
2414 cfg->link_freqs = devm_kcalloc(dev, in imx319_get_hwcfg()
2416 sizeof(*cfg->link_freqs), GFP_KERNEL); in imx319_get_hwcfg()
2417 if (!cfg->link_freqs) in imx319_get_hwcfg()
2421 cfg->link_freqs[i] = bus_cfg.link_frequencies[i]; in imx319_get_hwcfg()
2422 dev_dbg(dev, "link_freq[%d] = %lld", i, cfg->link_freqs[i]); in imx319_get_hwcfg()
2442 imx319 = devm_kzalloc(&client->dev, sizeof(*imx319), GFP_KERNEL); in imx319_probe()
2444 return -ENOMEM; in imx319_probe()
2446 mutex_init(&imx319->mutex); in imx319_probe()
2449 v4l2_i2c_subdev_init(&imx319->sd, client, &imx319_subdev_ops); in imx319_probe()
2451 full_power = acpi_dev_state_d0(&client->dev); in imx319_probe()
2456 dev_err(&client->dev, "failed to find sensor: %d", ret); in imx319_probe()
2461 imx319->hwcfg = imx319_get_hwcfg(&client->dev); in imx319_probe()
2462 if (!imx319->hwcfg) { in imx319_probe()
2463 dev_err(&client->dev, "failed to get hwcfg"); in imx319_probe()
2464 ret = -ENODEV; in imx319_probe()
2468 imx319->link_def_freq = link_freq_menu_items[IMX319_LINK_FREQ_INDEX]; in imx319_probe()
2469 for (i = 0; i < imx319->hwcfg->nr_of_link_freqs; i++) { in imx319_probe()
2470 if (imx319->hwcfg->link_freqs[i] == imx319->link_def_freq) { in imx319_probe()
2471 dev_dbg(&client->dev, "link freq index %d matched", i); in imx319_probe()
2476 if (i == imx319->hwcfg->nr_of_link_freqs) { in imx319_probe()
2477 dev_err(&client->dev, "no link frequency supported"); in imx319_probe()
2478 ret = -EINVAL; in imx319_probe()
2483 imx319->cur_mode = &supported_modes[0]; in imx319_probe()
2487 dev_err(&client->dev, "failed to init controls: %d", ret); in imx319_probe()
2492 imx319->sd.internal_ops = &imx319_internal_ops; in imx319_probe()
2493 imx319->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in imx319_probe()
2495 imx319->sd.entity.ops = &imx319_subdev_entity_ops; in imx319_probe()
2496 imx319->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx319_probe()
2499 imx319->pad.flags = MEDIA_PAD_FL_SOURCE; in imx319_probe()
2500 ret = media_entity_pads_init(&imx319->sd.entity, 1, &imx319->pad); in imx319_probe()
2502 dev_err(&client->dev, "failed to init entity pads: %d", ret); in imx319_probe()
2506 ret = v4l2_async_register_subdev_sensor(&imx319->sd); in imx319_probe()
2512 pm_runtime_set_active(&client->dev); in imx319_probe()
2513 pm_runtime_enable(&client->dev); in imx319_probe()
2514 pm_runtime_idle(&client->dev); in imx319_probe()
2519 media_entity_cleanup(&imx319->sd.entity); in imx319_probe()
2522 v4l2_ctrl_handler_free(imx319->sd.ctrl_handler); in imx319_probe()
2525 mutex_destroy(&imx319->mutex); in imx319_probe()
2536 media_entity_cleanup(&sd->entity); in imx319_remove()
2537 v4l2_ctrl_handler_free(sd->ctrl_handler); in imx319_remove()
2539 pm_runtime_disable(&client->dev); in imx319_remove()
2540 pm_runtime_set_suspended(&client->dev); in imx319_remove()
2542 mutex_destroy(&imx319->mutex); in imx319_remove()