• Home
  • Raw
  • Download

Lines Matching +full:xshutdown +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0
15 #include <media/v4l2-ctrls.h>
16 #include <media/v4l2-device.h>
17 #include <media/v4l2-event.h>
18 #include <media/v4l2-fwnode.h>
33 #define OV5670_MIPI_SC_CTRL0_LANES(v) ((((v) - 1) << 5) & \
38 /* vertical-timings from sensor */
43 /* horizontal-timings from sensor */
47 * Pixels-per-line(PPL) = Time-per-line * pixel-rate
48 * In OV5670, Time-per-line = HTS/SCLK.
138 * 0x3800-0x3807 in the modes register-value tables.
1878 /* Power-down and reset gpios. */
1880 struct gpio_desc *reset_gpio; /* XSHUTDOWN pin. */
1897 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_read_reg()
1905 return -EINVAL; in ov5670_read_reg()
1909 msgs[0].addr = client->addr; in ov5670_read_reg()
1915 msgs[1].addr = client->addr; in ov5670_read_reg()
1918 msgs[1].buf = &data_be_p[4 - len]; in ov5670_read_reg()
1920 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in ov5670_read_reg()
1922 return -EIO; in ov5670_read_reg()
1933 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_write_reg()
1941 return -EINVAL; in ov5670_write_reg()
1949 val_i = 4 - len; in ov5670_write_reg()
1955 return -EIO; in ov5670_write_reg()
1964 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_write_regs()
1972 &client->dev, in ov5670_write_regs()
1986 return ov5670_write_regs(ov5670, r_list->regs, r_list->num_of_regs); in ov5670_write_reg_list()
2035 struct ov5670 *ov5670 = container_of(ctrl->handler, in ov5670_set_ctrl()
2037 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_set_ctrl()
2042 switch (ctrl->id) { in ov5670_set_ctrl()
2045 max = ov5670->cur_mode->height + ctrl->val - 8; in ov5670_set_ctrl()
2046 __v4l2_ctrl_modify_range(ov5670->exposure, in ov5670_set_ctrl()
2047 ov5670->exposure->minimum, max, in ov5670_set_ctrl()
2048 ov5670->exposure->step, max); in ov5670_set_ctrl()
2053 if (!pm_runtime_get_if_in_use(&client->dev)) in ov5670_set_ctrl()
2056 switch (ctrl->id) { in ov5670_set_ctrl()
2059 OV5670_REG_VALUE_16BIT, ctrl->val); in ov5670_set_ctrl()
2062 ret = ov5670_update_digital_gain(ov5670, ctrl->val); in ov5670_set_ctrl()
2067 OV5670_REG_VALUE_24BIT, ctrl->val << 4); in ov5670_set_ctrl()
2073 ov5670->cur_mode->height + ctrl->val); in ov5670_set_ctrl()
2076 ret = ov5670_enable_test_pattern(ov5670, ctrl->val); in ov5670_set_ctrl()
2084 ret = -EINVAL; in ov5670_set_ctrl()
2085 dev_info(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n", in ov5670_set_ctrl()
2086 __func__, ctrl->id, ctrl->val); in ov5670_set_ctrl()
2090 pm_runtime_put(&client->dev); in ov5670_set_ctrl()
2103 &ov5670->endpoint.bus.mipi_csi2; in ov5670_init_controls()
2104 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_init_controls()
2115 ctrl_hdlr = &ov5670->ctrl_handler; in ov5670_init_controls()
2120 ctrl_hdlr->lock = &ov5670->mutex; in ov5670_init_controls()
2121 ov5670->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, in ov5670_init_controls()
2125 if (ov5670->link_freq) in ov5670_init_controls()
2126 ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5670_init_controls()
2129 lanes_count = bus_mipi_csi2->num_data_lanes; in ov5670_init_controls()
2132 ov5670->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, in ov5670_init_controls()
2139 vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height; in ov5670_init_controls()
2140 vblank_def = ov5670->cur_mode->vts_def - ov5670->cur_mode->height; in ov5670_init_controls()
2141 vblank_min = ov5670->cur_mode->vts_min - ov5670->cur_mode->height; in ov5670_init_controls()
2142 ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, in ov5670_init_controls()
2146 ov5670->hblank = v4l2_ctrl_new_std( in ov5670_init_controls()
2148 OV5670_FIXED_PPL - ov5670->cur_mode->width, in ov5670_init_controls()
2149 OV5670_FIXED_PPL - ov5670->cur_mode->width, 1, in ov5670_init_controls()
2150 OV5670_FIXED_PPL - ov5670->cur_mode->width); in ov5670_init_controls()
2151 if (ov5670->hblank) in ov5670_init_controls()
2152 ov5670->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5670_init_controls()
2165 exposure_max = ov5670->cur_mode->vts_def - 8; in ov5670_init_controls()
2166 ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, in ov5670_init_controls()
2174 ARRAY_SIZE(ov5670_test_pattern_menu) - 1, in ov5670_init_controls()
2177 if (ctrl_hdlr->error) { in ov5670_init_controls()
2178 ret = ctrl_hdlr->error; in ov5670_init_controls()
2182 ret = v4l2_fwnode_device_parse(&client->dev, &props); in ov5670_init_controls()
2191 ov5670->sd.ctrl_handler = ctrl_hdlr; in ov5670_init_controls()
2209 fmt->width = default_mode->width; in ov5670_init_cfg()
2210 fmt->height = default_mode->height; in ov5670_init_cfg()
2211 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; in ov5670_init_cfg()
2212 fmt->field = V4L2_FIELD_NONE; in ov5670_init_cfg()
2213 fmt->colorspace = V4L2_COLORSPACE_SRGB; in ov5670_init_cfg()
2214 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(V4L2_COLORSPACE_SRGB); in ov5670_init_cfg()
2215 fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; in ov5670_init_cfg()
2216 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(V4L2_COLORSPACE_SRGB); in ov5670_init_cfg()
2218 *crop = *default_mode->analog_crop; in ov5670_init_cfg()
2228 if (code->index > 0) in ov5670_enum_mbus_code()
2229 return -EINVAL; in ov5670_enum_mbus_code()
2231 code->code = MEDIA_BUS_FMT_SGRBG10_1X10; in ov5670_enum_mbus_code()
2240 if (fse->index >= ARRAY_SIZE(supported_modes)) in ov5670_enum_frame_size()
2241 return -EINVAL; in ov5670_enum_frame_size()
2243 if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10) in ov5670_enum_frame_size()
2244 return -EINVAL; in ov5670_enum_frame_size()
2246 fse->min_width = supported_modes[fse->index].width; in ov5670_enum_frame_size()
2247 fse->max_width = fse->min_width; in ov5670_enum_frame_size()
2248 fse->min_height = supported_modes[fse->index].height; in ov5670_enum_frame_size()
2249 fse->max_height = fse->min_height; in ov5670_enum_frame_size()
2257 fmt->format.width = mode->width; in ov5670_update_pad_format()
2258 fmt->format.height = mode->height; in ov5670_update_pad_format()
2259 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; in ov5670_update_pad_format()
2260 fmt->format.field = V4L2_FIELD_NONE; in ov5670_update_pad_format()
2267 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) in ov5670_do_get_pad_format()
2268 fmt->format = *v4l2_subdev_get_try_format(&ov5670->sd, in ov5670_do_get_pad_format()
2270 fmt->pad); in ov5670_do_get_pad_format()
2272 ov5670_update_pad_format(ov5670->cur_mode, fmt); in ov5670_do_get_pad_format()
2284 mutex_lock(&ov5670->mutex); in ov5670_get_pad_format()
2286 mutex_unlock(&ov5670->mutex); in ov5670_get_pad_format()
2297 &ov5670->endpoint.bus.mipi_csi2; in ov5670_set_pad_format()
2305 mutex_lock(&ov5670->mutex); in ov5670_set_pad_format()
2307 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; in ov5670_set_pad_format()
2312 fmt->format.width, fmt->format.height); in ov5670_set_pad_format()
2314 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in ov5670_set_pad_format()
2315 *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format; in ov5670_set_pad_format()
2317 ov5670->cur_mode = mode; in ov5670_set_pad_format()
2318 __v4l2_ctrl_s_ctrl(ov5670->link_freq, mode->link_freq_index); in ov5670_set_pad_format()
2320 lanes_count = bus_mipi_csi2->num_data_lanes; in ov5670_set_pad_format()
2321 link_freq = link_freq_menu_items[mode->link_freq_index]; in ov5670_set_pad_format()
2325 ov5670->pixel_rate, in ov5670_set_pad_format()
2328 vblank_def = ov5670->cur_mode->vts_def - in ov5670_set_pad_format()
2329 ov5670->cur_mode->height; in ov5670_set_pad_format()
2331 ov5670->vblank, in ov5670_set_pad_format()
2332 ov5670->cur_mode->vts_min - ov5670->cur_mode->height, in ov5670_set_pad_format()
2333 OV5670_VTS_MAX - ov5670->cur_mode->height, 1, in ov5670_set_pad_format()
2335 __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def); in ov5670_set_pad_format()
2336 h_blank = OV5670_FIXED_PPL - ov5670->cur_mode->width; in ov5670_set_pad_format()
2337 __v4l2_ctrl_modify_range(ov5670->hblank, h_blank, h_blank, 1, in ov5670_set_pad_format()
2341 mutex_unlock(&ov5670->mutex); in ov5670_set_pad_format()
2356 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_identify_module()
2360 if (ov5670->identified) in ov5670_identify_module()
2369 dev_err(&client->dev, "chip id mismatch: %x!=%x\n", in ov5670_identify_module()
2371 return -ENXIO; in ov5670_identify_module()
2374 ov5670->identified = true; in ov5670_identify_module()
2382 &ov5670->endpoint.bus.mipi_csi2; in ov5670_mipi_configure()
2383 unsigned int lanes_count = bus_mipi_csi2->num_data_lanes; in ov5670_mipi_configure()
2395 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_start_streaming()
2408 dev_err(&client->dev, "%s failed to set powerup registers\n", in ov5670_start_streaming()
2414 link_freq_index = ov5670->cur_mode->link_freq_index; in ov5670_start_streaming()
2418 dev_err(&client->dev, "%s failed to set plls\n", __func__); in ov5670_start_streaming()
2423 reg_list = &ov5670->cur_mode->reg_list; in ov5670_start_streaming()
2426 dev_err(&client->dev, "%s failed to set mode\n", __func__); in ov5670_start_streaming()
2432 dev_err(&client->dev, "%s failed to configure MIPI\n", __func__); in ov5670_start_streaming()
2436 ret = __v4l2_ctrl_handler_setup(ov5670->sd.ctrl_handler); in ov5670_start_streaming()
2444 dev_err(&client->dev, "%s failed to set stream\n", __func__); in ov5670_start_streaming()
2453 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_stop_streaming()
2459 dev_err(&client->dev, "%s failed to set stream\n", __func__); in ov5670_stop_streaming()
2473 mutex_lock(&ov5670->mutex); in ov5670_set_stream()
2474 if (ov5670->streaming == enable) in ov5670_set_stream()
2478 ret = pm_runtime_resume_and_get(&client->dev); in ov5670_set_stream()
2487 pm_runtime_put(&client->dev); in ov5670_set_stream()
2489 ov5670->streaming = enable; in ov5670_set_stream()
2493 pm_runtime_put(&client->dev); in ov5670_set_stream()
2496 mutex_unlock(&ov5670->mutex); in ov5670_set_stream()
2509 ret = clk_prepare_enable(ov5670->xvclk); in ov5670_runtime_resume()
2513 ret = regulator_bulk_enable(OV5670_NUM_SUPPLIES, ov5670->supplies); in ov5670_runtime_resume()
2515 clk_disable_unprepare(ov5670->xvclk); in ov5670_runtime_resume()
2519 gpiod_set_value_cansleep(ov5670->pwdn_gpio, 0); in ov5670_runtime_resume()
2520 gpiod_set_value_cansleep(ov5670->reset_gpio, 0); in ov5670_runtime_resume()
2536 gpiod_set_value_cansleep(ov5670->reset_gpio, 1); in ov5670_runtime_suspend()
2537 gpiod_set_value_cansleep(ov5670->pwdn_gpio, 1); in ov5670_runtime_suspend()
2538 regulator_bulk_disable(OV5670_NUM_SUPPLIES, ov5670->supplies); in ov5670_runtime_suspend()
2539 clk_disable_unprepare(ov5670->xvclk); in ov5670_runtime_suspend()
2549 if (ov5670->streaming) in ov5670_suspend()
2561 if (ov5670->streaming) { in ov5670_resume()
2582 const struct ov5670_mode *mode = sensor->cur_mode; in __ov5670_get_pad_crop()
2586 return v4l2_subdev_get_try_crop(&sensor->sd, state, pad); in __ov5670_get_pad_crop()
2588 return mode->analog_crop; in __ov5670_get_pad_crop()
2600 switch (sel->target) { in ov5670_get_selection()
2602 mutex_lock(&sensor->mutex); in ov5670_get_selection()
2603 sel->r = *__ov5670_get_pad_crop(sensor, state, sel->pad, in ov5670_get_selection()
2604 sel->which); in ov5670_get_selection()
2605 mutex_unlock(&sensor->mutex); in ov5670_get_selection()
2609 sel->r.top = 0; in ov5670_get_selection()
2610 sel->r.left = 0; in ov5670_get_selection()
2611 sel->r.width = OV5670_NATIVE_WIDTH; in ov5670_get_selection()
2612 sel->r.height = OV5670_NATIVE_HEIGHT; in ov5670_get_selection()
2615 sel->r = ov5670_analog_crop; in ov5670_get_selection()
2618 return -EINVAL; in ov5670_get_selection()
2655 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_regulators_probe()
2659 ov5670->supplies[i].supply = ov5670_supply_names[i]; in ov5670_regulators_probe()
2661 return devm_regulator_bulk_get(&client->dev, OV5670_NUM_SUPPLIES, in ov5670_regulators_probe()
2662 ov5670->supplies); in ov5670_regulators_probe()
2667 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_gpio_probe()
2669 ov5670->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", in ov5670_gpio_probe()
2671 if (IS_ERR(ov5670->pwdn_gpio)) in ov5670_gpio_probe()
2672 return PTR_ERR(ov5670->pwdn_gpio); in ov5670_gpio_probe()
2674 ov5670->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", in ov5670_gpio_probe()
2676 if (IS_ERR(ov5670->reset_gpio)) in ov5670_gpio_probe()
2677 return PTR_ERR(ov5670->reset_gpio); in ov5670_gpio_probe()
2690 ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL); in ov5670_probe()
2692 return -ENOMEM; in ov5670_probe()
2694 ov5670->xvclk = devm_clk_get_optional(&client->dev, NULL); in ov5670_probe()
2695 if (!IS_ERR_OR_NULL(ov5670->xvclk)) in ov5670_probe()
2696 input_clk = clk_get_rate(ov5670->xvclk); in ov5670_probe()
2697 else if (!ov5670->xvclk || PTR_ERR(ov5670->xvclk) == -ENOENT) in ov5670_probe()
2698 device_property_read_u32(&client->dev, "clock-frequency", in ov5670_probe()
2701 return dev_err_probe(&client->dev, PTR_ERR(ov5670->xvclk), in ov5670_probe()
2705 dev_err(&client->dev, in ov5670_probe()
2707 return -EINVAL; in ov5670_probe()
2711 v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops); in ov5670_probe()
2715 return dev_err_probe(&client->dev, ret, "Regulators probe failed\n"); in ov5670_probe()
2719 return dev_err_probe(&client->dev, ret, "GPIO probe failed\n"); in ov5670_probe()
2722 handle = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), NULL); in ov5670_probe()
2724 return dev_err_probe(&client->dev, -ENXIO, "Endpoint for node get failed\n"); in ov5670_probe()
2726 ov5670->endpoint.bus_type = V4L2_MBUS_CSI2_DPHY; in ov5670_probe()
2727 ov5670->endpoint.bus.mipi_csi2.num_data_lanes = 2; in ov5670_probe()
2729 ret = v4l2_fwnode_endpoint_alloc_parse(handle, &ov5670->endpoint); in ov5670_probe()
2732 return dev_err_probe(&client->dev, ret, "Endpoint parse failed\n"); in ov5670_probe()
2734 full_power = acpi_dev_state_d0(&client->dev); in ov5670_probe()
2736 ret = ov5670_runtime_resume(&client->dev); in ov5670_probe()
2738 dev_err_probe(&client->dev, ret, "Power up failed\n"); in ov5670_probe()
2745 dev_err_probe(&client->dev, ret, "ov5670_identify_module() error\n"); in ov5670_probe()
2750 mutex_init(&ov5670->mutex); in ov5670_probe()
2753 ov5670->cur_mode = &supported_modes[0]; in ov5670_probe()
2757 dev_err_probe(&client->dev, ret, "ov5670_init_controls() error\n"); in ov5670_probe()
2761 ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov5670_probe()
2763 ov5670->sd.entity.ops = &ov5670_subdev_entity_ops; in ov5670_probe()
2764 ov5670->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov5670_probe()
2767 ov5670->pad.flags = MEDIA_PAD_FL_SOURCE; in ov5670_probe()
2768 ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad); in ov5670_probe()
2770 dev_err_probe(&client->dev, ret, "media_entity_pads_init() error\n"); in ov5670_probe()
2774 ov5670->streaming = false; in ov5670_probe()
2778 pm_runtime_set_active(&client->dev); in ov5670_probe()
2779 pm_runtime_enable(&client->dev); in ov5670_probe()
2782 ret = v4l2_async_register_subdev_sensor(&ov5670->sd); in ov5670_probe()
2784 dev_err_probe(&client->dev, ret, "v4l2_async_register_subdev() error\n"); in ov5670_probe()
2788 pm_runtime_idle(&client->dev); in ov5670_probe()
2793 pm_runtime_disable(&client->dev); in ov5670_probe()
2795 media_entity_cleanup(&ov5670->sd.entity); in ov5670_probe()
2798 v4l2_ctrl_handler_free(ov5670->sd.ctrl_handler); in ov5670_probe()
2801 mutex_destroy(&ov5670->mutex); in ov5670_probe()
2805 ov5670_runtime_suspend(&client->dev); in ov5670_probe()
2808 v4l2_fwnode_endpoint_free(&ov5670->endpoint); in ov5670_probe()
2819 media_entity_cleanup(&sd->entity); in ov5670_remove()
2820 v4l2_ctrl_handler_free(sd->ctrl_handler); in ov5670_remove()
2821 mutex_destroy(&ov5670->mutex); in ov5670_remove()
2823 pm_runtime_disable(&client->dev); in ov5670_remove()
2824 ov5670_runtime_suspend(&client->dev); in ov5670_remove()
2826 v4l2_fwnode_endpoint_free(&ov5670->endpoint); in ov5670_remove()