• Home
  • Raw
  • Download

Lines Matching +full:clk +full:- +full:output +full:- +full:sel

15 #include <linux/clk.h>
26 #include <linux/v4l2-mediabus.h>
30 #include <media/v4l2-ctrls.h>
31 #include <media/v4l2-device.h>
32 #include <media/v4l2-fwnode.h>
33 #include <media/v4l2-subdev.h>
206 struct clk *clk; member
231 struct regmap *map = mt9v032->regmap; in mt9v032_update_aec_agc()
232 u16 value = mt9v032->aec_agc; in mt9v032_update_aec_agc()
244 mt9v032->aec_agc = value; in mt9v032_update_aec_agc()
251 struct v4l2_rect *crop = &mt9v032->crop; in mt9v032_update_hblank()
252 unsigned int min_hblank = mt9v032->model->data->min_hblank; in mt9v032_update_hblank()
255 if (mt9v032->version->version == MT9V034_CHIP_ID_REV1) in mt9v032_update_hblank()
256 min_hblank += (mt9v032->hratio - 1) * 10; in mt9v032_update_hblank()
257 min_hblank = max_t(int, mt9v032->model->data->min_row_time - crop->width, in mt9v032_update_hblank()
259 hblank = max_t(unsigned int, mt9v032->hblank, min_hblank); in mt9v032_update_hblank()
261 return regmap_write(mt9v032->regmap, MT9V032_HORIZONTAL_BLANKING, in mt9v032_update_hblank()
267 struct regmap *map = mt9v032->regmap; in mt9v032_power_on()
270 gpiod_set_value_cansleep(mt9v032->reset_gpio, 1); in mt9v032_power_on()
272 ret = clk_set_rate(mt9v032->clk, mt9v032->sysclk); in mt9v032_power_on()
277 ret = clk_prepare_enable(mt9v032->clk); in mt9v032_power_on()
283 if (mt9v032->reset_gpio) { in mt9v032_power_on()
284 gpiod_set_value_cansleep(mt9v032->reset_gpio, 0); in mt9v032_power_on()
311 clk_disable_unprepare(mt9v032->clk); in mt9v032_power_on()
317 clk_disable_unprepare(mt9v032->clk); in mt9v032_power_off()
322 struct regmap *map = mt9v032->regmap; in __mt9v032_set_power()
335 if (mt9v032->pdata && mt9v032->pdata->clk_pol) { in __mt9v032_set_power()
336 ret = regmap_write(map, mt9v032->model->data->pclk_reg, in __mt9v032_set_power()
347 return v4l2_ctrl_handler_setup(&mt9v032->ctrls); in __mt9v032_set_power()
350 /* -----------------------------------------------------------------------------
360 return v4l2_subdev_get_try_format(&mt9v032->subdev, cfg, pad); in __mt9v032_get_pad_format()
362 return &mt9v032->format; in __mt9v032_get_pad_format()
374 return v4l2_subdev_get_try_crop(&mt9v032->subdev, cfg, pad); in __mt9v032_get_pad_crop()
376 return &mt9v032->crop; in __mt9v032_get_pad_crop()
387 struct v4l2_rect *crop = &mt9v032->crop; in mt9v032_s_stream()
388 struct regmap *map = mt9v032->regmap; in mt9v032_s_stream()
397 hbin = fls(mt9v032->hratio) - 1; in mt9v032_s_stream()
398 vbin = fls(mt9v032->vratio) - 1; in mt9v032_s_stream()
406 ret = regmap_write(map, MT9V032_COLUMN_START, crop->left); in mt9v032_s_stream()
410 ret = regmap_write(map, MT9V032_ROW_START, crop->top); in mt9v032_s_stream()
414 ret = regmap_write(map, MT9V032_WINDOW_WIDTH, crop->width); in mt9v032_s_stream()
418 ret = regmap_write(map, MT9V032_WINDOW_HEIGHT, crop->height); in mt9v032_s_stream()
436 if (code->index > 0) in mt9v032_enum_mbus_code()
437 return -EINVAL; in mt9v032_enum_mbus_code()
439 code->code = mt9v032->format.code; in mt9v032_enum_mbus_code()
449 if (fse->index >= 3) in mt9v032_enum_frame_size()
450 return -EINVAL; in mt9v032_enum_frame_size()
451 if (mt9v032->format.code != fse->code) in mt9v032_enum_frame_size()
452 return -EINVAL; in mt9v032_enum_frame_size()
454 fse->min_width = MT9V032_WINDOW_WIDTH_DEF / (1 << fse->index); in mt9v032_enum_frame_size()
455 fse->max_width = fse->min_width; in mt9v032_enum_frame_size()
456 fse->min_height = MT9V032_WINDOW_HEIGHT_DEF / (1 << fse->index); in mt9v032_enum_frame_size()
457 fse->max_height = fse->min_height; in mt9v032_enum_frame_size()
468 format->format = *__mt9v032_get_pad_format(mt9v032, cfg, format->pad, in mt9v032_get_format()
469 format->which); in mt9v032_get_format()
475 struct i2c_client *client = v4l2_get_subdevdata(&mt9v032->subdev); in mt9v032_configure_pixel_rate()
478 ret = v4l2_ctrl_s_ctrl_int64(mt9v032->pixel_rate, in mt9v032_configure_pixel_rate()
479 mt9v032->sysclk / mt9v032->hratio); in mt9v032_configure_pixel_rate()
481 dev_warn(&client->dev, "failed to set pixel rate (%d)\n", ret); in mt9v032_configure_pixel_rate()
484 static unsigned int mt9v032_calc_ratio(unsigned int input, unsigned int output) in mt9v032_calc_ratio() argument
486 /* Compute the power-of-two binning factor closest to the input size to in mt9v032_calc_ratio()
487 * output size ratio. Given that the output size is bounded by input/4 in mt9v032_calc_ratio()
490 if (output * 3 > input * 2) in mt9v032_calc_ratio()
492 if (output * 3 > input) in mt9v032_calc_ratio()
509 __crop = __mt9v032_get_pad_crop(mt9v032, cfg, format->pad, in mt9v032_set_format()
510 format->which); in mt9v032_set_format()
513 width = clamp(ALIGN(format->format.width, 2), in mt9v032_set_format()
514 max_t(unsigned int, __crop->width / 4, in mt9v032_set_format()
516 __crop->width); in mt9v032_set_format()
517 height = clamp(ALIGN(format->format.height, 2), in mt9v032_set_format()
518 max_t(unsigned int, __crop->height / 4, in mt9v032_set_format()
520 __crop->height); in mt9v032_set_format()
522 hratio = mt9v032_calc_ratio(__crop->width, width); in mt9v032_set_format()
523 vratio = mt9v032_calc_ratio(__crop->height, height); in mt9v032_set_format()
525 __format = __mt9v032_get_pad_format(mt9v032, cfg, format->pad, in mt9v032_set_format()
526 format->which); in mt9v032_set_format()
527 __format->width = __crop->width / hratio; in mt9v032_set_format()
528 __format->height = __crop->height / vratio; in mt9v032_set_format()
530 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) { in mt9v032_set_format()
531 mt9v032->hratio = hratio; in mt9v032_set_format()
532 mt9v032->vratio = vratio; in mt9v032_set_format()
536 format->format = *__format; in mt9v032_set_format()
543 struct v4l2_subdev_selection *sel) in mt9v032_get_selection() argument
547 if (sel->target != V4L2_SEL_TGT_CROP) in mt9v032_get_selection()
548 return -EINVAL; in mt9v032_get_selection()
550 sel->r = *__mt9v032_get_pad_crop(mt9v032, cfg, sel->pad, sel->which); in mt9v032_get_selection()
556 struct v4l2_subdev_selection *sel) in mt9v032_set_selection() argument
563 if (sel->target != V4L2_SEL_TGT_CROP) in mt9v032_set_selection()
564 return -EINVAL; in mt9v032_set_selection()
569 rect.left = clamp(ALIGN(sel->r.left + 1, 2) - 1, in mt9v032_set_selection()
572 rect.top = clamp(ALIGN(sel->r.top + 1, 2) - 1, in mt9v032_set_selection()
575 rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2), in mt9v032_set_selection()
578 rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2), in mt9v032_set_selection()
583 rect.width, MT9V032_PIXEL_ARRAY_WIDTH - rect.left); in mt9v032_set_selection()
585 rect.height, MT9V032_PIXEL_ARRAY_HEIGHT - rect.top); in mt9v032_set_selection()
587 __crop = __mt9v032_get_pad_crop(mt9v032, cfg, sel->pad, sel->which); in mt9v032_set_selection()
589 if (rect.width != __crop->width || rect.height != __crop->height) { in mt9v032_set_selection()
590 /* Reset the output image size if the crop rectangle size has in mt9v032_set_selection()
593 __format = __mt9v032_get_pad_format(mt9v032, cfg, sel->pad, in mt9v032_set_selection()
594 sel->which); in mt9v032_set_selection()
595 __format->width = rect.width; in mt9v032_set_selection()
596 __format->height = rect.height; in mt9v032_set_selection()
597 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) { in mt9v032_set_selection()
598 mt9v032->hratio = 1; in mt9v032_set_selection()
599 mt9v032->vratio = 1; in mt9v032_set_selection()
605 sel->r = rect; in mt9v032_set_selection()
610 /* -----------------------------------------------------------------------------
624 * Possible values are 0-2. 0 means no LPF. For 1 and 2 this equation is used:
626 * if |(calculated new exp - current exp)| > (current exp / 4)
629 * next exp = current exp + ((calculated new exp - current exp) / 2^LPF)
647 container_of(ctrl->handler, struct mt9v032, ctrls); in mt9v032_s_ctrl()
648 struct regmap *map = mt9v032->regmap; in mt9v032_s_ctrl()
652 switch (ctrl->id) { in mt9v032_s_ctrl()
655 ctrl->val); in mt9v032_s_ctrl()
658 return regmap_write(map, MT9V032_ANALOG_GAIN, ctrl->val); in mt9v032_s_ctrl()
662 !ctrl->val); in mt9v032_s_ctrl()
666 ctrl->val); in mt9v032_s_ctrl()
669 mt9v032->hblank = ctrl->val; in mt9v032_s_ctrl()
674 ctrl->val); in mt9v032_s_ctrl()
678 if (mt9v032->link_freq == NULL) in mt9v032_s_ctrl()
681 freq = mt9v032->pdata->link_freqs[mt9v032->link_freq->val]; in mt9v032_s_ctrl()
682 *mt9v032->pixel_rate->p_new.p_s64 = freq; in mt9v032_s_ctrl()
683 mt9v032->sysclk = freq; in mt9v032_s_ctrl()
687 switch (mt9v032->test_pattern->val) { in mt9v032_s_ctrl()
704 data = (mt9v032->test_pattern_color->val << in mt9v032_s_ctrl()
714 return regmap_write(map, MT9V032_AEGC_DESIRED_BIN, ctrl->val); in mt9v032_s_ctrl()
717 return regmap_write(map, MT9V032_AEC_LPF, ctrl->val); in mt9v032_s_ctrl()
720 return regmap_write(map, MT9V032_AGC_LPF, ctrl->val); in mt9v032_s_ctrl()
724 ctrl->val); in mt9v032_s_ctrl()
728 ctrl->val); in mt9v032_s_ctrl()
732 mt9v032->model->data->aec_max_shutter_reg, in mt9v032_s_ctrl()
733 ctrl->val); in mt9v032_s_ctrl()
841 /* -----------------------------------------------------------------------------
850 mutex_lock(&mt9v032->power_lock); in mt9v032_set_power()
855 if (mt9v032->power_count == !on) { in mt9v032_set_power()
862 mt9v032->power_count += on ? 1 : -1; in mt9v032_set_power()
863 WARN_ON(mt9v032->power_count < 0); in mt9v032_set_power()
866 mutex_unlock(&mt9v032->power_lock); in mt9v032_set_power()
870 /* -----------------------------------------------------------------------------
882 dev_info(&client->dev, "Probing MT9V032 at address 0x%02x\n", in mt9v032_registered()
883 client->addr); in mt9v032_registered()
887 dev_err(&client->dev, "MT9V032 power up failed\n"); in mt9v032_registered()
892 ret = regmap_read(mt9v032->regmap, MT9V032_CHIP_VERSION, &version); in mt9v032_registered()
897 dev_err(&client->dev, "Failed reading chip version\n"); in mt9v032_registered()
903 mt9v032->version = &mt9v032_versions[i]; in mt9v032_registered()
908 if (mt9v032->version == NULL) { in mt9v032_registered()
909 dev_err(&client->dev, "Unsupported chip version 0x%04x\n", in mt9v032_registered()
911 return -ENODEV; in mt9v032_registered()
914 dev_info(&client->dev, "%s detected at address 0x%02x\n", in mt9v032_registered()
915 mt9v032->version->name, client->addr); in mt9v032_registered()
928 crop = v4l2_subdev_get_try_crop(subdev, fh->pad, 0); in mt9v032_open()
929 crop->left = MT9V032_COLUMN_START_DEF; in mt9v032_open()
930 crop->top = MT9V032_ROW_START_DEF; in mt9v032_open()
931 crop->width = MT9V032_WINDOW_WIDTH_DEF; in mt9v032_open()
932 crop->height = MT9V032_WINDOW_HEIGHT_DEF; in mt9v032_open()
934 format = v4l2_subdev_get_try_format(subdev, fh->pad, 0); in mt9v032_open()
936 if (mt9v032->model->color) in mt9v032_open()
937 format->code = MEDIA_BUS_FMT_SGRBG10_1X10; in mt9v032_open()
939 format->code = MEDIA_BUS_FMT_Y10_1X10; in mt9v032_open()
941 format->width = MT9V032_WINDOW_WIDTH_DEF; in mt9v032_open()
942 format->height = MT9V032_WINDOW_HEIGHT_DEF; in mt9v032_open()
943 format->field = V4L2_FIELD_NONE; in mt9v032_open()
944 format->colorspace = V4L2_COLORSPACE_SRGB; in mt9v032_open()
990 /* -----------------------------------------------------------------------------
1002 if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) in mt9v032_get_pdata()
1003 return client->dev.platform_data; in mt9v032_get_pdata()
1005 np = of_graph_get_next_endpoint(client->dev.of_node, NULL); in mt9v032_get_pdata()
1012 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); in mt9v032_get_pdata()
1016 prop = of_find_property(np, "link-frequencies", NULL); in mt9v032_get_pdata()
1019 size_t size = prop->length / sizeof(*link_freqs); in mt9v032_get_pdata()
1021 link_freqs = devm_kcalloc(&client->dev, size, in mt9v032_get_pdata()
1026 if (of_property_read_u64_array(np, "link-frequencies", in mt9v032_get_pdata()
1030 pdata->link_freqs = link_freqs; in mt9v032_get_pdata()
1031 pdata->link_def_freq = link_freqs[0]; in mt9v032_get_pdata()
1034 pdata->clk_pol = !!(endpoint.bus.parallel.flags & in mt9v032_get_pdata()
1050 mt9v032 = devm_kzalloc(&client->dev, sizeof(*mt9v032), GFP_KERNEL); in mt9v032_probe()
1052 return -ENOMEM; in mt9v032_probe()
1054 mt9v032->regmap = devm_regmap_init_i2c(client, &mt9v032_regmap_config); in mt9v032_probe()
1055 if (IS_ERR(mt9v032->regmap)) in mt9v032_probe()
1056 return PTR_ERR(mt9v032->regmap); in mt9v032_probe()
1058 mt9v032->clk = devm_clk_get(&client->dev, NULL); in mt9v032_probe()
1059 if (IS_ERR(mt9v032->clk)) in mt9v032_probe()
1060 return PTR_ERR(mt9v032->clk); in mt9v032_probe()
1062 mt9v032->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", in mt9v032_probe()
1064 if (IS_ERR(mt9v032->reset_gpio)) in mt9v032_probe()
1065 return PTR_ERR(mt9v032->reset_gpio); in mt9v032_probe()
1067 mt9v032->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby", in mt9v032_probe()
1069 if (IS_ERR(mt9v032->standby_gpio)) in mt9v032_probe()
1070 return PTR_ERR(mt9v032->standby_gpio); in mt9v032_probe()
1072 mutex_init(&mt9v032->power_lock); in mt9v032_probe()
1073 mt9v032->pdata = pdata; in mt9v032_probe()
1074 mt9v032->model = (const void *)did->driver_data; in mt9v032_probe()
1076 v4l2_ctrl_handler_init(&mt9v032->ctrls, 11 + in mt9v032_probe()
1079 v4l2_ctrl_new_std(&mt9v032->ctrls, &mt9v032_ctrl_ops, in mt9v032_probe()
1081 v4l2_ctrl_new_std(&mt9v032->ctrls, &mt9v032_ctrl_ops, in mt9v032_probe()
1084 v4l2_ctrl_new_std_menu(&mt9v032->ctrls, &mt9v032_ctrl_ops, in mt9v032_probe()
1087 v4l2_ctrl_new_std(&mt9v032->ctrls, &mt9v032_ctrl_ops, in mt9v032_probe()
1088 V4L2_CID_EXPOSURE, mt9v032->model->data->min_shutter, in mt9v032_probe()
1089 mt9v032->model->data->max_shutter, 1, in mt9v032_probe()
1091 v4l2_ctrl_new_std(&mt9v032->ctrls, &mt9v032_ctrl_ops, in mt9v032_probe()
1092 V4L2_CID_HBLANK, mt9v032->model->data->min_hblank, in mt9v032_probe()
1095 v4l2_ctrl_new_std(&mt9v032->ctrls, &mt9v032_ctrl_ops, in mt9v032_probe()
1096 V4L2_CID_VBLANK, mt9v032->model->data->min_vblank, in mt9v032_probe()
1097 mt9v032->model->data->max_vblank, 1, in mt9v032_probe()
1099 mt9v032->test_pattern = v4l2_ctrl_new_std_menu_items(&mt9v032->ctrls, in mt9v032_probe()
1101 ARRAY_SIZE(mt9v032_test_pattern_menu) - 1, 0, 0, in mt9v032_probe()
1103 mt9v032->test_pattern_color = v4l2_ctrl_new_custom(&mt9v032->ctrls, in mt9v032_probe()
1106 v4l2_ctrl_new_custom(&mt9v032->ctrls, in mt9v032_probe()
1107 mt9v032->model->data->aec_max_shutter_v4l2_ctrl, in mt9v032_probe()
1110 v4l2_ctrl_new_custom(&mt9v032->ctrls, &mt9v032_aegc_controls[i], in mt9v032_probe()
1113 v4l2_ctrl_cluster(2, &mt9v032->test_pattern); in mt9v032_probe()
1115 mt9v032->pixel_rate = in mt9v032_probe()
1116 v4l2_ctrl_new_std(&mt9v032->ctrls, &mt9v032_ctrl_ops, in mt9v032_probe()
1119 if (pdata && pdata->link_freqs) { in mt9v032_probe()
1122 for (i = 0; pdata->link_freqs[i]; ++i) { in mt9v032_probe()
1123 if (pdata->link_freqs[i] == pdata->link_def_freq) in mt9v032_probe()
1127 mt9v032->link_freq = in mt9v032_probe()
1128 v4l2_ctrl_new_int_menu(&mt9v032->ctrls, in mt9v032_probe()
1130 V4L2_CID_LINK_FREQ, i - 1, def, in mt9v032_probe()
1131 pdata->link_freqs); in mt9v032_probe()
1132 v4l2_ctrl_cluster(2, &mt9v032->link_freq); in mt9v032_probe()
1136 mt9v032->subdev.ctrl_handler = &mt9v032->ctrls; in mt9v032_probe()
1138 if (mt9v032->ctrls.error) { in mt9v032_probe()
1139 dev_err(&client->dev, "control initialization error %d\n", in mt9v032_probe()
1140 mt9v032->ctrls.error); in mt9v032_probe()
1141 ret = mt9v032->ctrls.error; in mt9v032_probe()
1145 mt9v032->crop.left = MT9V032_COLUMN_START_DEF; in mt9v032_probe()
1146 mt9v032->crop.top = MT9V032_ROW_START_DEF; in mt9v032_probe()
1147 mt9v032->crop.width = MT9V032_WINDOW_WIDTH_DEF; in mt9v032_probe()
1148 mt9v032->crop.height = MT9V032_WINDOW_HEIGHT_DEF; in mt9v032_probe()
1150 if (mt9v032->model->color) in mt9v032_probe()
1151 mt9v032->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; in mt9v032_probe()
1153 mt9v032->format.code = MEDIA_BUS_FMT_Y10_1X10; in mt9v032_probe()
1155 mt9v032->format.width = MT9V032_WINDOW_WIDTH_DEF; in mt9v032_probe()
1156 mt9v032->format.height = MT9V032_WINDOW_HEIGHT_DEF; in mt9v032_probe()
1157 mt9v032->format.field = V4L2_FIELD_NONE; in mt9v032_probe()
1158 mt9v032->format.colorspace = V4L2_COLORSPACE_SRGB; in mt9v032_probe()
1160 mt9v032->hratio = 1; in mt9v032_probe()
1161 mt9v032->vratio = 1; in mt9v032_probe()
1163 mt9v032->aec_agc = MT9V032_AEC_ENABLE | MT9V032_AGC_ENABLE; in mt9v032_probe()
1164 mt9v032->hblank = MT9V032_HORIZONTAL_BLANKING_DEF; in mt9v032_probe()
1165 mt9v032->sysclk = MT9V032_SYSCLK_FREQ_DEF; in mt9v032_probe()
1167 v4l2_i2c_subdev_init(&mt9v032->subdev, client, &mt9v032_subdev_ops); in mt9v032_probe()
1168 mt9v032->subdev.internal_ops = &mt9v032_subdev_internal_ops; in mt9v032_probe()
1169 mt9v032->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in mt9v032_probe()
1171 mt9v032->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in mt9v032_probe()
1172 mt9v032->pad.flags = MEDIA_PAD_FL_SOURCE; in mt9v032_probe()
1173 ret = media_entity_pads_init(&mt9v032->subdev.entity, 1, &mt9v032->pad); in mt9v032_probe()
1177 mt9v032->subdev.dev = &client->dev; in mt9v032_probe()
1178 ret = v4l2_async_register_subdev(&mt9v032->subdev); in mt9v032_probe()
1185 media_entity_cleanup(&mt9v032->subdev.entity); in mt9v032_probe()
1186 v4l2_ctrl_handler_free(&mt9v032->ctrls); in mt9v032_probe()
1196 v4l2_ctrl_handler_free(&mt9v032->ctrls); in mt9v032_remove()
1197 media_entity_cleanup(&subdev->entity); in mt9v032_remove()