Lines Matching refs:gc4653

120 struct gc4653 {  struct
161 #define to_gc4653(sd) container_of(sd, struct gc4653, subdev) argument
487 gc4653_find_best_fit(struct gc4653 *gc4653, struct v4l2_subdev_format *fmt) in gc4653_find_best_fit() argument
495 for (i = 0; i < gc4653->cfg_num; i++) { in gc4653_find_best_fit()
510 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_set_fmt() local
514 mutex_lock(&gc4653->mutex); in gc4653_set_fmt()
516 mode = gc4653_find_best_fit(gc4653, fmt); in gc4653_set_fmt()
525 mutex_unlock(&gc4653->mutex); in gc4653_set_fmt()
529 gc4653->cur_mode = mode; in gc4653_set_fmt()
531 __v4l2_ctrl_modify_range(gc4653->hblank, h_blank, in gc4653_set_fmt()
534 __v4l2_ctrl_modify_range(gc4653->vblank, vblank_def, in gc4653_set_fmt()
538 gc4653->cur_link_freq = 0; in gc4653_set_fmt()
539 gc4653->cur_pixel_rate = GC4653_PIXEL_RATE_LINEAR; in gc4653_set_fmt()
541 __v4l2_ctrl_s_ctrl_int64(gc4653->pixel_rate, in gc4653_set_fmt()
542 gc4653->cur_pixel_rate); in gc4653_set_fmt()
543 __v4l2_ctrl_s_ctrl(gc4653->link_freq, in gc4653_set_fmt()
544 gc4653->cur_link_freq); in gc4653_set_fmt()
545 gc4653->cur_vts = mode->vts_def; in gc4653_set_fmt()
547 mutex_unlock(&gc4653->mutex); in gc4653_set_fmt()
556 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_get_fmt() local
557 const struct gc4653_mode *mode = gc4653->cur_mode; in gc4653_get_fmt()
559 mutex_lock(&gc4653->mutex); in gc4653_get_fmt()
564 mutex_unlock(&gc4653->mutex); in gc4653_get_fmt()
573 mutex_unlock(&gc4653->mutex); in gc4653_get_fmt()
582 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_enum_mbus_code() local
586 code->code = gc4653->cur_mode->bus_fmt; in gc4653_enum_mbus_code()
595 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_enum_frame_sizes() local
597 if (fse->index >= gc4653->cfg_num) in gc4653_enum_frame_sizes()
611 static int gc4653_enable_test_pattern(struct gc4653 *gc4653, u32 pattern) in gc4653_enable_test_pattern() argument
620 return gc4653_write_reg(gc4653->client, GC4653_REG_TEST_PATTERN, in gc4653_enable_test_pattern()
624 static int gc4653_set_gain_reg(struct gc4653 *gc4653, u32 gain) in gc4653_set_gain_reg() argument
642 gc4653_write_reg(gc4653->client, 0x2b3, in gc4653_set_gain_reg()
644 gc4653_write_reg(gc4653->client, 0x2b4, in gc4653_set_gain_reg()
646 gc4653_write_reg(gc4653->client, 0x2b8, in gc4653_set_gain_reg()
648 gc4653_write_reg(gc4653->client, 0x2b9, in gc4653_set_gain_reg()
650 gc4653_write_reg(gc4653->client, 0x515, in gc4653_set_gain_reg()
652 gc4653_write_reg(gc4653->client, 0x519, in gc4653_set_gain_reg()
654 gc4653_write_reg(gc4653->client, 0x2d9, in gc4653_set_gain_reg()
658 gc4653_write_reg(gc4653->client, 0x20e, in gc4653_set_gain_reg()
660 gc4653_write_reg(gc4653->client, 0x20f, in gc4653_set_gain_reg()
668 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_g_frame_interval() local
669 const struct gc4653_mode *mode = gc4653->cur_mode; in gc4653_g_frame_interval()
679 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_g_mbus_config() local
680 const struct gc4653_mode *mode = gc4653->cur_mode; in gc4653_g_mbus_config()
694 static void gc4653_get_module_inf(struct gc4653 *gc4653, in gc4653_get_module_inf() argument
699 strscpy(inf->base.module, gc4653->module_name, in gc4653_get_module_inf()
701 strscpy(inf->base.lens, gc4653->len_name, sizeof(inf->base.lens)); in gc4653_get_module_inf()
704 static int gc4653_get_channel_info(struct gc4653 *gc4653, struct rkmodule_channel_info *ch_info) in gc4653_get_channel_info() argument
708 ch_info->vc = gc4653->cur_mode->vc[ch_info->index]; in gc4653_get_channel_info()
709 ch_info->width = gc4653->cur_mode->width; in gc4653_get_channel_info()
710 ch_info->height = gc4653->cur_mode->height; in gc4653_get_channel_info()
711 ch_info->bus_fmt = gc4653->cur_mode->bus_fmt; in gc4653_get_channel_info()
717 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_ioctl() local
726 gc4653_get_module_inf(gc4653, (struct rkmodule_inf *)arg); in gc4653_ioctl()
731 hdr->hdr_mode = gc4653->cur_mode->hdr_mode; in gc4653_ioctl()
735 w = gc4653->cur_mode->width; in gc4653_ioctl()
736 h = gc4653->cur_mode->height; in gc4653_ioctl()
737 for (i = 0; i < gc4653->cfg_num; i++) { in gc4653_ioctl()
741 gc4653->cur_mode = &supported_modes[i]; in gc4653_ioctl()
745 if (i == gc4653->cfg_num) { in gc4653_ioctl()
746 dev_err(&gc4653->client->dev, in gc4653_ioctl()
751 w = gc4653->cur_mode->hts_def - in gc4653_ioctl()
752 gc4653->cur_mode->width; in gc4653_ioctl()
753 h = gc4653->cur_mode->vts_def - in gc4653_ioctl()
754 gc4653->cur_mode->height; in gc4653_ioctl()
755 __v4l2_ctrl_modify_range(gc4653->hblank, w, w, 1, w); in gc4653_ioctl()
756 __v4l2_ctrl_modify_range(gc4653->vblank, h, in gc4653_ioctl()
758 gc4653->cur_mode->height, in gc4653_ioctl()
760 gc4653->cur_link_freq = 0; in gc4653_ioctl()
761 gc4653->cur_pixel_rate = GC4653_PIXEL_RATE_LINEAR; in gc4653_ioctl()
763 __v4l2_ctrl_s_ctrl_int64(gc4653->pixel_rate, in gc4653_ioctl()
764 gc4653->cur_pixel_rate); in gc4653_ioctl()
765 __v4l2_ctrl_s_ctrl(gc4653->link_freq, in gc4653_ioctl()
766 gc4653->cur_link_freq); in gc4653_ioctl()
767 gc4653->cur_vts = gc4653->cur_mode->vts_def; in gc4653_ioctl()
775 ret = gc4653_write_reg(gc4653->client, GC4653_REG_CTRL_MODE, in gc4653_ioctl()
778 ret = gc4653_write_reg(gc4653->client, GC4653_REG_CTRL_MODE, in gc4653_ioctl()
783 ret = gc4653_get_channel_info(gc4653, ch_info); in gc4653_ioctl()
910 static int __gc4653_start_stream(struct gc4653 *gc4653) in __gc4653_start_stream() argument
914 ret = gc4653_write_array(gc4653->client, gc4653->cur_mode->reg_list); in __gc4653_start_stream()
919 ret = __v4l2_ctrl_handler_setup(&gc4653->ctrl_handler); in __gc4653_start_stream()
920 if (gc4653->has_init_exp && gc4653->cur_mode->hdr_mode != NO_HDR) { in __gc4653_start_stream()
921 ret = gc4653_ioctl(&gc4653->subdev, PREISP_CMD_SET_HDRAE_EXP, in __gc4653_start_stream()
922 &gc4653->init_hdrae_exp); in __gc4653_start_stream()
924 dev_err(&gc4653->client->dev, in __gc4653_start_stream()
932 ret |= gc4653_write_reg(gc4653->client, GC4653_REG_CTRL_MODE, in __gc4653_start_stream()
934 if (gc4653->cur_mode->hdr_mode == NO_HDR) in __gc4653_start_stream()
935 ret |= gc4653_write_array(gc4653->client, gc4653_otp_regs); in __gc4653_start_stream()
939 static int __gc4653_stop_stream(struct gc4653 *gc4653) in __gc4653_stop_stream() argument
941 gc4653->has_init_exp = false; in __gc4653_stop_stream()
942 return gc4653_write_reg(gc4653->client, GC4653_REG_CTRL_MODE, in __gc4653_stop_stream()
948 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_s_stream() local
949 struct i2c_client *client = gc4653->client; in gc4653_s_stream()
952 mutex_lock(&gc4653->mutex); in gc4653_s_stream()
954 if (on == gc4653->streaming) in gc4653_s_stream()
964 ret = __gc4653_start_stream(gc4653); in gc4653_s_stream()
971 __gc4653_stop_stream(gc4653); in gc4653_s_stream()
975 gc4653->streaming = on; in gc4653_s_stream()
978 mutex_unlock(&gc4653->mutex); in gc4653_s_stream()
985 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_s_power() local
986 struct i2c_client *client = gc4653->client; in gc4653_s_power()
989 mutex_lock(&gc4653->mutex); in gc4653_s_power()
992 if (gc4653->power_on == !!on) in gc4653_s_power()
1002 ret = gc4653_write_array(gc4653->client, gc4653_global_regs); in gc4653_s_power()
1009 gc4653->power_on = true; in gc4653_s_power()
1012 gc4653->power_on = false; in gc4653_s_power()
1016 mutex_unlock(&gc4653->mutex); in gc4653_s_power()
1027 static int __gc4653_power_on(struct gc4653 *gc4653) in __gc4653_power_on() argument
1031 struct device *dev = &gc4653->client->dev; in __gc4653_power_on()
1033 if (!IS_ERR_OR_NULL(gc4653->pins_default)) { in __gc4653_power_on()
1034 ret = pinctrl_select_state(gc4653->pinctrl, in __gc4653_power_on()
1035 gc4653->pins_default); in __gc4653_power_on()
1039 ret = clk_set_rate(gc4653->xvclk, GC4653_XVCLK_FREQ); in __gc4653_power_on()
1042 if (clk_get_rate(gc4653->xvclk) != GC4653_XVCLK_FREQ) in __gc4653_power_on()
1044 ret = clk_prepare_enable(gc4653->xvclk); in __gc4653_power_on()
1049 if (!IS_ERR(gc4653->reset_gpio)) in __gc4653_power_on()
1050 gpiod_set_value_cansleep(gc4653->reset_gpio, 0); in __gc4653_power_on()
1052 if (!IS_ERR(gc4653->pwdn_gpio)) in __gc4653_power_on()
1053 gpiod_set_value_cansleep(gc4653->pwdn_gpio, 0); in __gc4653_power_on()
1056 ret = regulator_bulk_enable(GC4653_NUM_SUPPLIES, gc4653->supplies); in __gc4653_power_on()
1063 if (!IS_ERR(gc4653->pwren_gpio)) in __gc4653_power_on()
1064 gpiod_set_value_cansleep(gc4653->pwren_gpio, 1); in __gc4653_power_on()
1067 if (!IS_ERR(gc4653->pwdn_gpio)) in __gc4653_power_on()
1068 gpiod_set_value_cansleep(gc4653->pwdn_gpio, 1); in __gc4653_power_on()
1070 if (!IS_ERR(gc4653->reset_gpio)) in __gc4653_power_on()
1071 gpiod_set_value_cansleep(gc4653->reset_gpio, 1); in __gc4653_power_on()
1080 clk_disable_unprepare(gc4653->xvclk); in __gc4653_power_on()
1085 static void __gc4653_power_off(struct gc4653 *gc4653) in __gc4653_power_off() argument
1088 struct device *dev = &gc4653->client->dev; in __gc4653_power_off()
1090 if (!IS_ERR(gc4653->pwdn_gpio)) in __gc4653_power_off()
1091 gpiod_set_value_cansleep(gc4653->pwdn_gpio, 0); in __gc4653_power_off()
1092 clk_disable_unprepare(gc4653->xvclk); in __gc4653_power_off()
1093 if (!IS_ERR(gc4653->reset_gpio)) in __gc4653_power_off()
1094 gpiod_set_value_cansleep(gc4653->reset_gpio, 0); in __gc4653_power_off()
1095 if (!IS_ERR_OR_NULL(gc4653->pins_sleep)) { in __gc4653_power_off()
1096 ret = pinctrl_select_state(gc4653->pinctrl, in __gc4653_power_off()
1097 gc4653->pins_sleep); in __gc4653_power_off()
1101 regulator_bulk_disable(GC4653_NUM_SUPPLIES, gc4653->supplies); in __gc4653_power_off()
1102 if (!IS_ERR(gc4653->pwren_gpio)) in __gc4653_power_off()
1103 gpiod_set_value_cansleep(gc4653->pwren_gpio, 0); in __gc4653_power_off()
1110 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_runtime_resume() local
1112 return __gc4653_power_on(gc4653); in gc4653_runtime_resume()
1119 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_runtime_suspend() local
1121 __gc4653_power_off(gc4653); in gc4653_runtime_suspend()
1129 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_open() local
1134 mutex_lock(&gc4653->mutex); in gc4653_open()
1141 mutex_unlock(&gc4653->mutex); in gc4653_open()
1152 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_enum_frame_interval() local
1154 if (fie->index >= gc4653->cfg_num) in gc4653_enum_frame_interval()
1206 struct gc4653 *gc4653 = container_of(ctrl->handler, in gc4653_set_ctrl() local
1207 struct gc4653, ctrl_handler); in gc4653_set_ctrl()
1208 struct i2c_client *client = gc4653->client; in gc4653_set_ctrl()
1217 max = gc4653->cur_mode->height + ctrl->val - 4; in gc4653_set_ctrl()
1218 __v4l2_ctrl_modify_range(gc4653->exposure, in gc4653_set_ctrl()
1219 gc4653->exposure->minimum, in gc4653_set_ctrl()
1221 gc4653->exposure->step, in gc4653_set_ctrl()
1222 gc4653->exposure->default_value); in gc4653_set_ctrl()
1232 ret = gc4653_write_reg(gc4653->client, GC4653_REG_EXPOSURE_H, in gc4653_set_ctrl()
1235 ret |= gc4653_write_reg(gc4653->client, GC4653_REG_EXPOSURE_L, in gc4653_set_ctrl()
1240 ret = gc4653_set_gain_reg(gc4653, ctrl->val); in gc4653_set_ctrl()
1243 gc4653->cur_vts = ctrl->val + gc4653->cur_mode->height; in gc4653_set_ctrl()
1244 ret = gc4653_write_reg(gc4653->client, GC4653_REG_VTS_H, in gc4653_set_ctrl()
1246 gc4653->cur_vts >> 8); in gc4653_set_ctrl()
1247 ret |= gc4653_write_reg(gc4653->client, GC4653_REG_VTS_L, in gc4653_set_ctrl()
1249 gc4653->cur_vts & 0xff); in gc4653_set_ctrl()
1252 ret = gc4653_enable_test_pattern(gc4653, ctrl->val); in gc4653_set_ctrl()
1255 ret = gc4653_read_reg(gc4653->client, GC4653_FLIP_MIRROR_REG, in gc4653_set_ctrl()
1261 ret |= gc4653_write_reg(gc4653->client, GC4653_FRAME_BUFFER_REG, in gc4653_set_ctrl()
1263 ret |= gc4653_write_reg(gc4653->client, GC4653_FLIP_MIRROR_REG, in gc4653_set_ctrl()
1265 ret |= gc4653_write_reg(gc4653->client, GC4653_FRAME_BUFFER_REG, in gc4653_set_ctrl()
1269 ret = gc4653_read_reg(gc4653->client, GC4653_FLIP_MIRROR_REG, in gc4653_set_ctrl()
1275 ret |= gc4653_write_reg(gc4653->client, GC4653_FRAME_BUFFER_REG, in gc4653_set_ctrl()
1277 ret |= gc4653_write_reg(gc4653->client, GC4653_FLIP_MIRROR_REG, in gc4653_set_ctrl()
1279 ret |= gc4653_write_reg(gc4653->client, GC4653_FRAME_BUFFER_REG, in gc4653_set_ctrl()
1297 static int gc4653_initialize_controls(struct gc4653 *gc4653) in gc4653_initialize_controls() argument
1305 handler = &gc4653->ctrl_handler; in gc4653_initialize_controls()
1306 mode = gc4653->cur_mode; in gc4653_initialize_controls()
1310 handler->lock = &gc4653->mutex; in gc4653_initialize_controls()
1312 gc4653->link_freq = v4l2_ctrl_new_int_menu(handler, NULL, V4L2_CID_LINK_FREQ, in gc4653_initialize_controls()
1314 gc4653->cur_link_freq = 0; in gc4653_initialize_controls()
1315 gc4653->cur_pixel_rate = GC4653_PIXEL_RATE_LINEAR; in gc4653_initialize_controls()
1317 __v4l2_ctrl_s_ctrl(gc4653->link_freq, in gc4653_initialize_controls()
1318 gc4653->cur_link_freq); in gc4653_initialize_controls()
1320 gc4653->pixel_rate = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, in gc4653_initialize_controls()
1324 gc4653->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in gc4653_initialize_controls()
1326 if (gc4653->hblank) in gc4653_initialize_controls()
1327 gc4653->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in gc4653_initialize_controls()
1330 gc4653->cur_vts = mode->vts_def; in gc4653_initialize_controls()
1331 gc4653->vblank = v4l2_ctrl_new_std(handler, &gc4653_ctrl_ops, in gc4653_initialize_controls()
1337 gc4653->exposure = v4l2_ctrl_new_std(handler, &gc4653_ctrl_ops, in gc4653_initialize_controls()
1344 gc4653->anal_gain = v4l2_ctrl_new_std(handler, &gc4653_ctrl_ops, in gc4653_initialize_controls()
1351 gc4653->test_pattern = in gc4653_initialize_controls()
1358 gc4653->h_flip = v4l2_ctrl_new_std(handler, &gc4653_ctrl_ops, in gc4653_initialize_controls()
1361 gc4653->v_flip = v4l2_ctrl_new_std(handler, &gc4653_ctrl_ops, in gc4653_initialize_controls()
1365 dev_err(&gc4653->client->dev, in gc4653_initialize_controls()
1370 gc4653->subdev.ctrl_handler = handler; in gc4653_initialize_controls()
1371 gc4653->has_init_exp = false; in gc4653_initialize_controls()
1381 static int gc4653_check_sensor_id(struct gc4653 *gc4653, in gc4653_check_sensor_id() argument
1384 struct device *dev = &gc4653->client->dev; in gc4653_check_sensor_id()
1404 static int gc4653_configure_regulators(struct gc4653 *gc4653) in gc4653_configure_regulators() argument
1409 gc4653->supplies[i].supply = gc4653_supply_names[i]; in gc4653_configure_regulators()
1411 return devm_regulator_bulk_get(&gc4653->client->dev, in gc4653_configure_regulators()
1413 gc4653->supplies); in gc4653_configure_regulators()
1421 struct gc4653 *gc4653; in gc4653_probe() local
1432 gc4653 = devm_kzalloc(dev, sizeof(*gc4653), GFP_KERNEL); in gc4653_probe()
1433 if (!gc4653) in gc4653_probe()
1438 &gc4653->module_index); in gc4653_probe()
1440 &gc4653->module_facing); in gc4653_probe()
1442 &gc4653->module_name); in gc4653_probe()
1444 &gc4653->len_name); in gc4653_probe()
1450 gc4653->client = client; in gc4653_probe()
1451 gc4653->cfg_num = ARRAY_SIZE(supported_modes); in gc4653_probe()
1452 for (i = 0; i < gc4653->cfg_num; i++) { in gc4653_probe()
1454 gc4653->cur_mode = &supported_modes[i]; in gc4653_probe()
1458 if (i == gc4653->cfg_num) in gc4653_probe()
1459 gc4653->cur_mode = &supported_modes[0]; in gc4653_probe()
1461 gc4653->xvclk = devm_clk_get(dev, "xvclk"); in gc4653_probe()
1462 if (IS_ERR(gc4653->xvclk)) { in gc4653_probe()
1467 gc4653->pwren_gpio = devm_gpiod_get(dev, "pwren", GPIOD_OUT_LOW); in gc4653_probe()
1468 if (IS_ERR(gc4653->pwren_gpio)) in gc4653_probe()
1471 gc4653->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in gc4653_probe()
1472 if (IS_ERR(gc4653->reset_gpio)) in gc4653_probe()
1475 gc4653->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in gc4653_probe()
1476 if (IS_ERR(gc4653->pwdn_gpio)) in gc4653_probe()
1479 gc4653->pinctrl = devm_pinctrl_get(dev); in gc4653_probe()
1480 if (!IS_ERR(gc4653->pinctrl)) { in gc4653_probe()
1481 gc4653->pins_default = in gc4653_probe()
1482 pinctrl_lookup_state(gc4653->pinctrl, in gc4653_probe()
1484 if (IS_ERR(gc4653->pins_default)) in gc4653_probe()
1487 gc4653->pins_sleep = in gc4653_probe()
1488 pinctrl_lookup_state(gc4653->pinctrl, in gc4653_probe()
1490 if (IS_ERR(gc4653->pins_sleep)) in gc4653_probe()
1496 ret = gc4653_configure_regulators(gc4653); in gc4653_probe()
1502 mutex_init(&gc4653->mutex); in gc4653_probe()
1504 sd = &gc4653->subdev; in gc4653_probe()
1506 ret = gc4653_initialize_controls(gc4653); in gc4653_probe()
1510 ret = __gc4653_power_on(gc4653); in gc4653_probe()
1516 ret = gc4653_check_sensor_id(gc4653, client); in gc4653_probe()
1526 gc4653->pad.flags = MEDIA_PAD_FL_SOURCE; in gc4653_probe()
1528 ret = media_entity_pads_init(&sd->entity, 1, &gc4653->pad); in gc4653_probe()
1534 if (strcmp(gc4653->module_facing, "back") == 0) in gc4653_probe()
1540 gc4653->module_index, facing, in gc4653_probe()
1559 __gc4653_power_off(gc4653); in gc4653_probe()
1561 v4l2_ctrl_handler_free(&gc4653->ctrl_handler); in gc4653_probe()
1563 mutex_destroy(&gc4653->mutex); in gc4653_probe()
1571 struct gc4653 *gc4653 = to_gc4653(sd); in gc4653_remove() local
1577 v4l2_ctrl_handler_free(&gc4653->ctrl_handler); in gc4653_remove()
1578 mutex_destroy(&gc4653->mutex); in gc4653_remove()
1582 __gc4653_power_off(gc4653); in gc4653_remove()