Lines Matching refs:gc2053

97 #define to_gc2053(sd) container_of(sd, struct gc2053, subdev)
116 struct gc2053 { struct
429 gc2053_find_best_fit(struct gc2053 *gc2053, struct v4l2_subdev_format *fmt) in gc2053_find_best_fit() argument
437 for (i = 0; i < gc2053->cfg_num; i++) { in gc2053_find_best_fit()
513 static int gc2053_set_gain(struct gc2053 *gc2053, u32 gain) in gc2053_set_gain() argument
529 ret = gc2053_write_reg(gc2053->client, 0xb4, gain_reg_table[i][0]); in gc2053_set_gain()
530 ret |= gc2053_write_reg(gc2053->client, 0xb3, gain_reg_table[i][1]); in gc2053_set_gain()
531 ret |= gc2053_write_reg(gc2053->client, 0xb8, gain_reg_table[i][2]); in gc2053_set_gain()
532 ret |= gc2053_write_reg(gc2053->client, 0xb9, gain_reg_table[i][3]); in gc2053_set_gain()
535 ret |= gc2053_write_reg(gc2053->client, 0xb1, (temp >> 6)); in gc2053_set_gain()
536 ret |= gc2053_write_reg(gc2053->client, 0xb2, (temp << 2) & 0xfc); in gc2053_set_gain()
543 struct gc2053 *gc2053 = container_of(ctrl->handler, in gc2053_set_ctrl() local
544 struct gc2053, ctrl_handler); in gc2053_set_ctrl()
545 struct i2c_client *client = gc2053->client; in gc2053_set_ctrl()
554 max = gc2053->cur_mode->height + ctrl->val - 4; in gc2053_set_ctrl()
555 __v4l2_ctrl_modify_range(gc2053->exposure, in gc2053_set_ctrl()
556 gc2053->exposure->minimum, max, in gc2053_set_ctrl()
557 gc2053->exposure->step, in gc2053_set_ctrl()
558 gc2053->exposure->default_value); in gc2053_set_ctrl()
567 ret = gc2053_write_reg(gc2053->client, GC2053_REG_EXP_H, in gc2053_set_ctrl()
569 ret |= gc2053_write_reg(gc2053->client, GC2053_REG_EXP_L, in gc2053_set_ctrl()
573 gc2053_set_gain(gc2053, ctrl->val); in gc2053_set_ctrl()
576 vts = ctrl->val + gc2053->cur_mode->height; in gc2053_set_ctrl()
578 if (gc2053->sync_mode == INTERNAL_MASTER_MODE) in gc2053_set_ctrl()
580 ret = gc2053_write_reg(gc2053->client, GC2053_REG_VTS_H, (vts >> 8) & 0x3f); in gc2053_set_ctrl()
581 ret |= gc2053_write_reg(gc2053->client, GC2053_REG_VTS_L, vts & 0xff); in gc2053_set_ctrl()
587 gc2053->flip |= GC_MIRROR_BIT_MASK; in gc2053_set_ctrl()
589 gc2053->flip &= ~GC_MIRROR_BIT_MASK; in gc2053_set_ctrl()
593 gc2053->flip |= GC_FLIP_BIT_MASK; in gc2053_set_ctrl()
595 gc2053->flip &= ~GC_FLIP_BIT_MASK; in gc2053_set_ctrl()
611 static int gc2053_configure_regulators(struct gc2053 *gc2053) in gc2053_configure_regulators() argument
616 gc2053->supplies[i].supply = gc2053_supply_names[i]; in gc2053_configure_regulators()
618 return devm_regulator_bulk_get(&gc2053->client->dev, in gc2053_configure_regulators()
620 gc2053->supplies); in gc2053_configure_regulators()
623 static int gc2053_parse_of(struct gc2053 *gc2053) in gc2053_parse_of() argument
625 struct device *dev = &gc2053->client->dev; in gc2053_parse_of()
642 gc2053->lane_num = rval; in gc2053_parse_of()
643 if (2 == gc2053->lane_num) { in gc2053_parse_of()
644 gc2053->cur_mode = &supported_modes[0]; in gc2053_parse_of()
645 gc2053->cfg_num = ARRAY_SIZE(supported_modes); in gc2053_parse_of()
648 gc2053->pixel_rate = MIPI_FREQ_297M * 2U * (gc2053->lane_num) / 10U; in gc2053_parse_of()
650 gc2053->lane_num, gc2053->pixel_rate); in gc2053_parse_of()
652 dev_info(dev, "gc2053 can not support the lane num(%d)\n", gc2053->lane_num); in gc2053_parse_of()
657 static int gc2053_initialize_controls(struct gc2053 *gc2053) in gc2053_initialize_controls() argument
666 handler = &gc2053->ctrl_handler; in gc2053_initialize_controls()
667 mode = gc2053->cur_mode; in gc2053_initialize_controls()
671 handler->lock = &gc2053->mutex; in gc2053_initialize_controls()
679 0, gc2053->pixel_rate, 1, gc2053->pixel_rate); in gc2053_initialize_controls()
682 gc2053->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in gc2053_initialize_controls()
684 if (gc2053->hblank) in gc2053_initialize_controls()
685 gc2053->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in gc2053_initialize_controls()
688 gc2053->vblank = v4l2_ctrl_new_std(handler, &gc2053_ctrl_ops, in gc2053_initialize_controls()
694 gc2053->exposure = v4l2_ctrl_new_std(handler, &gc2053_ctrl_ops, in gc2053_initialize_controls()
699 gc2053->anal_gain = v4l2_ctrl_new_std(handler, &gc2053_ctrl_ops, in gc2053_initialize_controls()
704 gc2053->h_flip = v4l2_ctrl_new_std(handler, &gc2053_ctrl_ops, in gc2053_initialize_controls()
707 gc2053->v_flip = v4l2_ctrl_new_std(handler, &gc2053_ctrl_ops, in gc2053_initialize_controls()
709 gc2053->flip = 0; in gc2053_initialize_controls()
713 dev_err(&gc2053->client->dev, in gc2053_initialize_controls()
718 gc2053->subdev.ctrl_handler = handler; in gc2053_initialize_controls()
732 static int __gc2053_power_on(struct gc2053 *gc2053) in __gc2053_power_on() argument
736 struct device *dev = &gc2053->client->dev; in __gc2053_power_on()
738 if (!IS_ERR_OR_NULL(gc2053->pins_default)) { in __gc2053_power_on()
739 ret = pinctrl_select_state(gc2053->pinctrl, in __gc2053_power_on()
740 gc2053->pins_default); in __gc2053_power_on()
745 ret = clk_set_rate(gc2053->xvclk, GC2053_XVCLK_FREQ); in __gc2053_power_on()
748 if (clk_get_rate(gc2053->xvclk) != GC2053_XVCLK_FREQ) in __gc2053_power_on()
750 ret = clk_prepare_enable(gc2053->xvclk); in __gc2053_power_on()
756 ret = regulator_bulk_enable(GC2053_NUM_SUPPLIES, gc2053->supplies); in __gc2053_power_on()
761 if (!IS_ERR(gc2053->power_gpio)) { in __gc2053_power_on()
762 gpiod_set_value_cansleep(gc2053->power_gpio, 1); in __gc2053_power_on()
765 if (!IS_ERR(gc2053->reset_gpio)) { in __gc2053_power_on()
766 gpiod_set_value_cansleep(gc2053->reset_gpio, 1); in __gc2053_power_on()
769 if (!IS_ERR(gc2053->pwdn_gpio)) in __gc2053_power_on()
770 gpiod_set_value_cansleep(gc2053->pwdn_gpio, 0); in __gc2053_power_on()
772 if (!IS_ERR(gc2053->reset_gpio)) in __gc2053_power_on()
773 gpiod_set_value_cansleep(gc2053->reset_gpio, 0); in __gc2053_power_on()
781 clk_disable_unprepare(gc2053->xvclk); in __gc2053_power_on()
785 static void __gc2053_power_off(struct gc2053 *gc2053) in __gc2053_power_off() argument
788 struct device *dev = &gc2053->client->dev; in __gc2053_power_off()
790 if (!IS_ERR(gc2053->pwdn_gpio)) in __gc2053_power_off()
791 gpiod_set_value_cansleep(gc2053->pwdn_gpio, 1); in __gc2053_power_off()
792 clk_disable_unprepare(gc2053->xvclk); in __gc2053_power_off()
794 if (!IS_ERR(gc2053->reset_gpio)) in __gc2053_power_off()
795 gpiod_set_value_cansleep(gc2053->reset_gpio, 1); in __gc2053_power_off()
797 if (!IS_ERR_OR_NULL(gc2053->pins_sleep)) { in __gc2053_power_off()
798 ret = pinctrl_select_state(gc2053->pinctrl, in __gc2053_power_off()
799 gc2053->pins_sleep); in __gc2053_power_off()
803 if (!IS_ERR(gc2053->power_gpio)) in __gc2053_power_off()
804 gpiod_set_value_cansleep(gc2053->power_gpio, 0); in __gc2053_power_off()
805 regulator_bulk_disable(GC2053_NUM_SUPPLIES, gc2053->supplies); in __gc2053_power_off()
808 static int gc2053_check_sensor_id(struct gc2053 *gc2053, in gc2053_check_sensor_id() argument
811 struct device *dev = &gc2053->client->dev; in gc2053_check_sensor_id()
836 static int gc2053_set_flip(struct gc2053 *gc2053, u8 mode) in gc2053_set_flip() argument
840 gc2053_read_reg(gc2053->client, GC2053_FLIP_MIRROR_REG, &match_reg); in gc2053_set_flip()
856 return gc2053_write_reg(gc2053->client, GC2053_FLIP_MIRROR_REG, match_reg); in gc2053_set_flip()
859 static int __gc2053_start_stream(struct gc2053 *gc2053) in __gc2053_start_stream() argument
861 struct i2c_client *client = gc2053->client; in __gc2053_start_stream()
864 ret = gc2053_write_array(client, gc2053->cur_mode->reg_list); in __gc2053_start_stream()
869 mutex_unlock(&gc2053->mutex); in __gc2053_start_stream()
870 ret = v4l2_ctrl_handler_setup(&gc2053->ctrl_handler); in __gc2053_start_stream()
871 mutex_lock(&gc2053->mutex); in __gc2053_start_stream()
873 ret |= gc2053_set_flip(gc2053, gc2053->flip); in __gc2053_start_stream()
876 if (gc2053->sync_mode == INTERNAL_MASTER_MODE) { in __gc2053_start_stream()
881 } else if (gc2053->sync_mode == EXTERNAL_MASTER_MODE) { in __gc2053_start_stream()
886 } else if (gc2053->sync_mode == SLAVE_MODE) { in __gc2053_start_stream()
887 ret = gc2053_write_array(gc2053->client, gc2053_slave_mode_regs); in __gc2053_start_stream()
892 ret = gc2053_write_reg(gc2053->client, GC2053_REG_CTRL_MODE, in __gc2053_start_stream()
898 static int __gc2053_stop_stream(struct gc2053 *gc2053) in __gc2053_stop_stream() argument
900 return gc2053_write_reg(gc2053->client, GC2053_REG_CTRL_MODE, in __gc2053_stop_stream()
904 static void gc2053_get_module_inf(struct gc2053 *gc2053, in gc2053_get_module_inf() argument
909 strlcpy(inf->base.module, gc2053->module_name, in gc2053_get_module_inf()
911 strlcpy(inf->base.lens, gc2053->len_name, sizeof(inf->base.lens)); in gc2053_get_module_inf()
914 static void gc2053_set_awb_cfg(struct gc2053 *gc2053, in gc2053_set_awb_cfg() argument
917 mutex_lock(&gc2053->mutex); in gc2053_set_awb_cfg()
918 memcpy(&gc2053->awb_cfg, cfg, sizeof(*cfg)); in gc2053_set_awb_cfg()
919 mutex_unlock(&gc2053->mutex); in gc2053_set_awb_cfg()
922 static void gc2053_set_lsc_cfg(struct gc2053 *gc2053, in gc2053_set_lsc_cfg() argument
925 mutex_lock(&gc2053->mutex); in gc2053_set_lsc_cfg()
926 memcpy(&gc2053->lsc_cfg, cfg, sizeof(*cfg)); in gc2053_set_lsc_cfg()
927 mutex_unlock(&gc2053->mutex); in gc2053_set_lsc_cfg()
932 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_ioctl() local
942 hdr_cfg->hdr_mode = gc2053->cur_mode->hdr_mode; in gc2053_ioctl()
945 gc2053_get_module_inf(gc2053, (struct rkmodule_inf *)arg); in gc2053_ioctl()
948 gc2053_set_awb_cfg(gc2053, (struct rkmodule_awb_cfg *)arg); in gc2053_ioctl()
951 gc2053_set_lsc_cfg(gc2053, (struct rkmodule_lsc_cfg *)arg); in gc2053_ioctl()
958 ret = gc2053_write_reg(gc2053->client, GC2053_REG_CTRL_MODE, in gc2053_ioctl()
961 ret = gc2053_write_reg(gc2053->client, GC2053_REG_CTRL_MODE, in gc2053_ioctl()
966 *sync_mode = gc2053->sync_mode; in gc2053_ioctl()
970 gc2053->sync_mode = *sync_mode; in gc2053_ioctl()
1099 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_s_stream() local
1100 struct i2c_client *client = gc2053->client; in gc2053_s_stream()
1103 mutex_lock(&gc2053->mutex); in gc2053_s_stream()
1105 if (on == gc2053->streaming) in gc2053_s_stream()
1115 ret = __gc2053_start_stream(gc2053); in gc2053_s_stream()
1122 __gc2053_stop_stream(gc2053); in gc2053_s_stream()
1126 gc2053->streaming = on; in gc2053_s_stream()
1129 mutex_unlock(&gc2053->mutex); in gc2053_s_stream()
1136 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_g_frame_interval() local
1137 const struct gc2053_mode *mode = gc2053->cur_mode; in gc2053_g_frame_interval()
1147 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_g_mbus_config() local
1148 const struct gc2053_mode *mode = gc2053->cur_mode; in gc2053_g_mbus_config()
1174 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_enum_frame_sizes() local
1176 if (fse->index >= gc2053->cfg_num) in gc2053_enum_frame_sizes()
1193 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_enum_frame_interval() local
1195 if (fie->index >= gc2053->cfg_num) in gc2053_enum_frame_interval()
1210 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_set_fmt() local
1214 mutex_lock(&gc2053->mutex); in gc2053_set_fmt()
1216 mode = gc2053_find_best_fit(gc2053, fmt); in gc2053_set_fmt()
1225 mutex_unlock(&gc2053->mutex); in gc2053_set_fmt()
1229 gc2053->cur_mode = mode; in gc2053_set_fmt()
1231 __v4l2_ctrl_modify_range(gc2053->hblank, h_blank, in gc2053_set_fmt()
1234 __v4l2_ctrl_modify_range(gc2053->vblank, vblank_def, in gc2053_set_fmt()
1239 mutex_unlock(&gc2053->mutex); in gc2053_set_fmt()
1247 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_get_fmt() local
1248 const struct gc2053_mode *mode = gc2053->cur_mode; in gc2053_get_fmt()
1250 mutex_lock(&gc2053->mutex); in gc2053_get_fmt()
1255 mutex_unlock(&gc2053->mutex); in gc2053_get_fmt()
1271 mutex_unlock(&gc2053->mutex); in gc2053_get_fmt()
1278 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_open() local
1283 mutex_lock(&gc2053->mutex); in gc2053_open()
1290 mutex_unlock(&gc2053->mutex); in gc2053_open()
1304 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_s_power() local
1305 struct i2c_client *client = gc2053->client; in gc2053_s_power()
1308 mutex_lock(&gc2053->mutex); in gc2053_s_power()
1311 if (gc2053->power_on == !!on) in gc2053_s_power()
1321 gc2053->power_on = true; in gc2053_s_power()
1324 gc2053->power_on = false; in gc2053_s_power()
1328 mutex_unlock(&gc2053->mutex); in gc2053_s_power()
1365 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_runtime_resume() local
1367 __gc2053_power_on(gc2053); in gc2053_runtime_resume()
1375 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_runtime_suspend() local
1377 __gc2053_power_off(gc2053); in gc2053_runtime_suspend()
1391 struct gc2053 *gc2053; in gc2053_probe() local
1402 gc2053 = devm_kzalloc(dev, sizeof(*gc2053), GFP_KERNEL); in gc2053_probe()
1403 if (!gc2053) in gc2053_probe()
1406 gc2053->client = client; in gc2053_probe()
1408 &gc2053->module_index); in gc2053_probe()
1410 &gc2053->module_facing); in gc2053_probe()
1412 &gc2053->module_name); in gc2053_probe()
1414 &gc2053->len_name); in gc2053_probe()
1424 gc2053->sync_mode = NO_SYNC_MODE; in gc2053_probe()
1428 gc2053->sync_mode = EXTERNAL_MASTER_MODE; in gc2053_probe()
1430 gc2053->sync_mode = INTERNAL_MASTER_MODE; in gc2053_probe()
1432 gc2053->sync_mode = SLAVE_MODE; in gc2053_probe()
1435 gc2053->xvclk = devm_clk_get(&client->dev, "xvclk"); in gc2053_probe()
1436 if (IS_ERR(gc2053->xvclk)) { in gc2053_probe()
1441 gc2053->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in gc2053_probe()
1442 if (IS_ERR(gc2053->reset_gpio)) in gc2053_probe()
1445 gc2053->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in gc2053_probe()
1446 if (IS_ERR(gc2053->pwdn_gpio)) in gc2053_probe()
1449 gc2053->power_gpio = devm_gpiod_get(dev, "power", GPIOD_OUT_LOW); in gc2053_probe()
1450 if (IS_ERR(gc2053->power_gpio)) in gc2053_probe()
1453 ret = gc2053_configure_regulators(gc2053); in gc2053_probe()
1459 ret = gc2053_parse_of(gc2053); in gc2053_probe()
1463 gc2053->pinctrl = devm_pinctrl_get(dev); in gc2053_probe()
1464 if (!IS_ERR(gc2053->pinctrl)) { in gc2053_probe()
1465 gc2053->pins_default = in gc2053_probe()
1466 pinctrl_lookup_state(gc2053->pinctrl, in gc2053_probe()
1468 if (IS_ERR(gc2053->pins_default)) in gc2053_probe()
1471 gc2053->pins_sleep = in gc2053_probe()
1472 pinctrl_lookup_state(gc2053->pinctrl, in gc2053_probe()
1474 if (IS_ERR(gc2053->pins_sleep)) in gc2053_probe()
1480 mutex_init(&gc2053->mutex); in gc2053_probe()
1482 sd = &gc2053->subdev; in gc2053_probe()
1484 ret = gc2053_initialize_controls(gc2053); in gc2053_probe()
1488 ret = __gc2053_power_on(gc2053); in gc2053_probe()
1492 ret = gc2053_check_sensor_id(gc2053, client); in gc2053_probe()
1501 gc2053->pad.flags = MEDIA_PAD_FL_SOURCE; in gc2053_probe()
1503 ret = media_entity_pads_init(&sd->entity, 1, &gc2053->pad); in gc2053_probe()
1509 if (strcmp(gc2053->module_facing, "back") == 0) in gc2053_probe()
1515 gc2053->module_index, facing, in gc2053_probe()
1536 __gc2053_power_off(gc2053); in gc2053_probe()
1538 v4l2_ctrl_handler_free(&gc2053->ctrl_handler); in gc2053_probe()
1541 mutex_destroy(&gc2053->mutex); in gc2053_probe()
1548 struct gc2053 *gc2053 = to_gc2053(sd); in gc2053_remove() local
1554 v4l2_ctrl_handler_free(&gc2053->ctrl_handler); in gc2053_remove()
1555 mutex_destroy(&gc2053->mutex); in gc2053_remove()
1559 __gc2053_power_off(gc2053); in gc2053_remove()