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
1670 .llp = 3968,
1682 .llp = 3968,
1694 .llp = 3968,
1706 .llp = 3968,
1718 .llp = 2500,
1730 .llp = 2500,
1742 .llp = 2500,
1754 .llp = 2500,
1768 /* Get bayer order based on flip setting. */
1781 lockdep_assert_held(&imx319->mutex); in imx319_get_format_code()
1782 code = codes[imx319->vflip->val][imx319->hflip->val]; in imx319_get_format_code()
1790 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_read_reg()
1797 return -EINVAL; in imx319_read_reg()
1801 msgs[0].addr = client->addr; in imx319_read_reg()
1807 msgs[1].addr = client->addr; in imx319_read_reg()
1810 msgs[1].buf = &data_buf[4 - len]; in imx319_read_reg()
1812 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in imx319_read_reg()
1814 return -EIO; in imx319_read_reg()
1824 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_write_reg()
1828 return -EINVAL; in imx319_write_reg()
1831 put_unaligned_be32(val << (8 * (4 - len)), buf + 2); in imx319_write_reg()
1833 return -EIO; in imx319_write_reg()
1842 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_write_regs()
1849 dev_err_ratelimited(&client->dev, in imx319_write_regs()
1859 /* Open sub-device */
1864 v4l2_subdev_state_get_format(fh->state, 0); in imx319_open()
1866 mutex_lock(&imx319->mutex); in imx319_open()
1869 try_fmt->width = imx319->cur_mode->width; in imx319_open()
1870 try_fmt->height = imx319->cur_mode->height; in imx319_open()
1871 try_fmt->code = imx319_get_format_code(imx319); in imx319_open()
1872 try_fmt->field = V4L2_FIELD_NONE; in imx319_open()
1874 mutex_unlock(&imx319->mutex); in imx319_open()
1881 struct imx319 *imx319 = container_of(ctrl->handler, in imx319_set_ctrl()
1883 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_set_ctrl()
1888 switch (ctrl->id) { in imx319_set_ctrl()
1891 max = imx319->cur_mode->height + ctrl->val - 18; in imx319_set_ctrl()
1892 __v4l2_ctrl_modify_range(imx319->exposure, in imx319_set_ctrl()
1893 imx319->exposure->minimum, in imx319_set_ctrl()
1894 max, imx319->exposure->step, max); in imx319_set_ctrl()
1902 if (!pm_runtime_get_if_in_use(&client->dev)) in imx319_set_ctrl()
1905 switch (ctrl->id) { in imx319_set_ctrl()
1907 /* Analog gain = 1024/(1024 - ctrl->val) times */ in imx319_set_ctrl()
1909 ctrl->val); in imx319_set_ctrl()
1913 ctrl->val); in imx319_set_ctrl()
1917 ctrl->val); in imx319_set_ctrl()
1922 imx319->cur_mode->height + ctrl->val); in imx319_set_ctrl()
1926 2, ctrl->val); in imx319_set_ctrl()
1931 imx319->hflip->val | in imx319_set_ctrl()
1932 imx319->vflip->val << 1); in imx319_set_ctrl()
1935 ret = -EINVAL; in imx319_set_ctrl()
1936 dev_info(&client->dev, "ctrl(id:0x%x,val:0x%x) is not handled", in imx319_set_ctrl()
1937 ctrl->id, ctrl->val); in imx319_set_ctrl()
1941 pm_runtime_put(&client->dev); in imx319_set_ctrl()
1956 if (code->index > 0) in imx319_enum_mbus_code()
1957 return -EINVAL; in imx319_enum_mbus_code()
1959 mutex_lock(&imx319->mutex); in imx319_enum_mbus_code()
1960 code->code = imx319_get_format_code(imx319); in imx319_enum_mbus_code()
1961 mutex_unlock(&imx319->mutex); in imx319_enum_mbus_code()
1972 if (fse->index >= ARRAY_SIZE(supported_modes)) in imx319_enum_frame_size()
1973 return -EINVAL; in imx319_enum_frame_size()
1975 mutex_lock(&imx319->mutex); in imx319_enum_frame_size()
1976 if (fse->code != imx319_get_format_code(imx319)) { in imx319_enum_frame_size()
1977 mutex_unlock(&imx319->mutex); in imx319_enum_frame_size()
1978 return -EINVAL; in imx319_enum_frame_size()
1980 mutex_unlock(&imx319->mutex); in imx319_enum_frame_size()
1982 fse->min_width = supported_modes[fse->index].width; in imx319_enum_frame_size()
1983 fse->max_width = fse->min_width; in imx319_enum_frame_size()
1984 fse->min_height = supported_modes[fse->index].height; in imx319_enum_frame_size()
1985 fse->max_height = fse->min_height; in imx319_enum_frame_size()
1994 fmt->format.width = mode->width; in imx319_update_pad_format()
1995 fmt->format.height = mode->height; in imx319_update_pad_format()
1996 fmt->format.code = imx319_get_format_code(imx319); in imx319_update_pad_format()
1997 fmt->format.field = V4L2_FIELD_NONE; in imx319_update_pad_format()
2006 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in imx319_do_get_pad_format()
2007 framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad); in imx319_do_get_pad_format()
2008 fmt->format = *framefmt; in imx319_do_get_pad_format()
2010 imx319_update_pad_format(imx319, imx319->cur_mode, fmt); in imx319_do_get_pad_format()
2023 mutex_lock(&imx319->mutex); in imx319_get_pad_format()
2025 mutex_unlock(&imx319->mutex); in imx319_get_pad_format()
2044 mutex_lock(&imx319->mutex); in imx319_set_pad_format()
2050 fmt->format.code = imx319_get_format_code(imx319); in imx319_set_pad_format()
2055 fmt->format.width, fmt->format.height); in imx319_set_pad_format()
2057 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in imx319_set_pad_format()
2058 framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad); in imx319_set_pad_format()
2059 *framefmt = fmt->format; in imx319_set_pad_format()
2061 imx319->cur_mode = mode; in imx319_set_pad_format()
2064 __v4l2_ctrl_s_ctrl_int64(imx319->pixel_rate, pixel_rate); in imx319_set_pad_format()
2066 height = imx319->cur_mode->height; in imx319_set_pad_format()
2067 vblank_def = imx319->cur_mode->fll_def - height; in imx319_set_pad_format()
2068 vblank_min = imx319->cur_mode->fll_min - height; in imx319_set_pad_format()
2069 height = IMX319_FLL_MAX - height; in imx319_set_pad_format()
2070 __v4l2_ctrl_modify_range(imx319->vblank, vblank_min, height, 1, in imx319_set_pad_format()
2072 __v4l2_ctrl_s_ctrl(imx319->vblank, vblank_def); in imx319_set_pad_format()
2073 h_blank = mode->llp - imx319->cur_mode->width; in imx319_set_pad_format()
2078 __v4l2_ctrl_modify_range(imx319->hblank, h_blank, in imx319_set_pad_format()
2082 mutex_unlock(&imx319->mutex); in imx319_set_pad_format()
2090 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_identify_module()
2094 if (imx319->identified) in imx319_identify_module()
2102 dev_err(&client->dev, "chip id mismatch: %x!=%x", in imx319_identify_module()
2104 return -EIO; in imx319_identify_module()
2107 imx319->identified = true; in imx319_identify_module()
2115 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_start_streaming()
2125 ret = imx319_write_regs(imx319, reg_list->regs, reg_list->num_of_regs); in imx319_start_streaming()
2127 dev_err(&client->dev, "failed to set global settings"); in imx319_start_streaming()
2132 reg_list = &imx319->cur_mode->reg_list; in imx319_start_streaming()
2133 ret = imx319_write_regs(imx319, reg_list->regs, reg_list->num_of_regs); in imx319_start_streaming()
2135 dev_err(&client->dev, "failed to set mode"); in imx319_start_streaming()
2145 ret = __v4l2_ctrl_handler_setup(imx319->sd.ctrl_handler); in imx319_start_streaming()
2166 mutex_lock(&imx319->mutex); in imx319_set_stream()
2169 ret = pm_runtime_resume_and_get(&client->dev); in imx319_set_stream()
2182 pm_runtime_put(&client->dev); in imx319_set_stream()
2186 __v4l2_ctrl_grab(imx319->vflip, enable); in imx319_set_stream()
2187 __v4l2_ctrl_grab(imx319->hflip, enable); in imx319_set_stream()
2189 mutex_unlock(&imx319->mutex); in imx319_set_stream()
2194 pm_runtime_put(&client->dev); in imx319_set_stream()
2196 mutex_unlock(&imx319->mutex); in imx319_set_stream()
2234 struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); in imx319_init_controls()
2245 ctrl_hdlr = &imx319->ctrl_handler; in imx319_init_controls()
2250 ctrl_hdlr->lock = &imx319->mutex; in imx319_init_controls()
2251 max = ARRAY_SIZE(link_freq_menu_items) - 1; in imx319_init_controls()
2252 imx319->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2255 if (imx319->link_freq) in imx319_init_controls()
2256 imx319->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx319_init_controls()
2262 imx319->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2266 /* Initial vblank/hblank/exposure parameters based on current mode */ in imx319_init_controls()
2267 mode = imx319->cur_mode; in imx319_init_controls()
2268 vblank_def = mode->fll_def - mode->height; in imx319_init_controls()
2269 vblank_min = mode->fll_min - mode->height; in imx319_init_controls()
2270 imx319->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2272 IMX319_FLL_MAX - mode->height, in imx319_init_controls()
2275 hblank = mode->llp - mode->width; in imx319_init_controls()
2276 imx319->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2279 if (imx319->hblank) in imx319_init_controls()
2280 imx319->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx319_init_controls()
2283 exposure_max = mode->fll_def - 18; in imx319_init_controls()
2284 imx319->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2290 imx319->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2292 if (imx319->hflip) in imx319_init_controls()
2293 imx319->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx319_init_controls()
2294 imx319->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx319_ctrl_ops, in imx319_init_controls()
2296 if (imx319->vflip) in imx319_init_controls()
2297 imx319->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx319_init_controls()
2310 ARRAY_SIZE(imx319_test_pattern_menu) - 1, in imx319_init_controls()
2312 if (ctrl_hdlr->error) { in imx319_init_controls()
2313 ret = ctrl_hdlr->error; in imx319_init_controls()
2314 dev_err(&client->dev, "control init failed: %d", ret); in imx319_init_controls()
2318 imx319->sd.ctrl_handler = ctrl_hdlr; in imx319_init_controls()
2353 ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency", in imx319_get_hwcfg()
2354 &cfg->ext_clk); in imx319_get_hwcfg()
2360 dev_dbg(dev, "ext clk: %d", cfg->ext_clk); in imx319_get_hwcfg()
2361 if (cfg->ext_clk != IMX319_EXT_CLK) { in imx319_get_hwcfg()
2363 cfg->ext_clk); in imx319_get_hwcfg()
2371 &cfg->link_freq_bitmap); in imx319_get_hwcfg()
2391 imx319 = devm_kzalloc(&client->dev, sizeof(*imx319), GFP_KERNEL); in imx319_probe()
2393 return -ENOMEM; in imx319_probe()
2395 mutex_init(&imx319->mutex); in imx319_probe()
2398 v4l2_i2c_subdev_init(&imx319->sd, client, &imx319_subdev_ops); in imx319_probe()
2400 full_power = acpi_dev_state_d0(&client->dev); in imx319_probe()
2405 dev_err(&client->dev, "failed to find sensor: %d", ret); in imx319_probe()
2410 imx319->hwcfg = imx319_get_hwcfg(&client->dev); in imx319_probe()
2411 if (!imx319->hwcfg) { in imx319_probe()
2412 dev_err(&client->dev, "failed to get hwcfg"); in imx319_probe()
2413 ret = -ENODEV; in imx319_probe()
2418 imx319->cur_mode = &supported_modes[0]; in imx319_probe()
2422 dev_err(&client->dev, "failed to init controls: %d", ret); in imx319_probe()
2427 imx319->sd.internal_ops = &imx319_internal_ops; in imx319_probe()
2428 imx319->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in imx319_probe()
2430 imx319->sd.entity.ops = &imx319_subdev_entity_ops; in imx319_probe()
2431 imx319->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx319_probe()
2434 imx319->pad.flags = MEDIA_PAD_FL_SOURCE; in imx319_probe()
2435 ret = media_entity_pads_init(&imx319->sd.entity, 1, &imx319->pad); in imx319_probe()
2437 dev_err(&client->dev, "failed to init entity pads: %d", ret); in imx319_probe()
2443 pm_runtime_set_active(&client->dev); in imx319_probe()
2444 pm_runtime_enable(&client->dev); in imx319_probe()
2445 pm_runtime_idle(&client->dev); in imx319_probe()
2447 ret = v4l2_async_register_subdev_sensor(&imx319->sd); in imx319_probe()
2454 pm_runtime_disable(&client->dev); in imx319_probe()
2455 pm_runtime_set_suspended(&client->dev); in imx319_probe()
2456 media_entity_cleanup(&imx319->sd.entity); in imx319_probe()
2459 v4l2_ctrl_handler_free(imx319->sd.ctrl_handler); in imx319_probe()
2462 mutex_destroy(&imx319->mutex); in imx319_probe()
2473 media_entity_cleanup(&sd->entity); in imx319_remove()
2474 v4l2_ctrl_handler_free(sd->ctrl_handler); in imx319_remove()
2476 pm_runtime_disable(&client->dev); in imx319_remove()
2477 pm_runtime_set_suspended(&client->dev); in imx319_remove()
2479 mutex_destroy(&imx319->mutex); in imx319_remove()