Lines Matching refs:tp2855

85 struct tp2855 {  struct
116 #define to_tp2855(sd) container_of(sd, struct tp2855, subdev) argument
352 tp2855_find_best_fit(struct tp2855 *tp2855, in tp2855_find_best_fit() argument
361 for (i = 0; i < tp2855->cfg_num; i++) { in tp2855_find_best_fit()
377 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_set_fmt() local
381 mutex_lock(&tp2855->mutex); in tp2855_set_fmt()
383 mode = tp2855_find_best_fit(tp2855, fmt); in tp2855_set_fmt()
394 mutex_unlock(&tp2855->mutex); in tp2855_set_fmt()
398 __v4l2_ctrl_s_ctrl(tp2855->link_freq, mode->mipi_freq_idx); in tp2855_set_fmt()
400 __v4l2_ctrl_s_ctrl_int64(tp2855->pixel_rate, pixel_rate); in tp2855_set_fmt()
401 dev_dbg(&tp2855->client->dev, "mipi_freq_idx %d\n", mode->mipi_freq_idx); in tp2855_set_fmt()
402 dev_dbg(&tp2855->client->dev, "pixel_rate %lld\n", pixel_rate); in tp2855_set_fmt()
405 mutex_unlock(&tp2855->mutex); in tp2855_set_fmt()
413 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_get_fmt() local
414 struct i2c_client *client = tp2855->client; in tp2855_get_fmt()
415 const struct tp2855_mode *mode = tp2855->cur_mode; in tp2855_get_fmt()
417 mutex_lock(&tp2855->mutex); in tp2855_get_fmt()
422 mutex_unlock(&tp2855->mutex); in tp2855_get_fmt()
435 mutex_unlock(&tp2855->mutex); in tp2855_get_fmt()
449 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_enum_mbus_code() local
453 code->code = tp2855->cur_mode->bus_fmt; in tp2855_enum_mbus_code()
462 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_enum_frame_sizes() local
463 struct i2c_client *client = tp2855->client; in tp2855_enum_frame_sizes()
467 if (fse->index >= tp2855->cfg_num) in tp2855_enum_frame_sizes()
490 static void tp2855_get_module_inf(struct tp2855 *tp2855, in tp2855_get_module_inf() argument
495 strlcpy(inf->base.module, tp2855->module_name, in tp2855_get_module_inf()
497 strlcpy(inf->base.lens, tp2855->len_name, sizeof(inf->base.lens)); in tp2855_get_module_inf()
502 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_ioctl() local
507 tp2855_get_module_inf(tp2855, (struct rkmodule_inf *)arg); in tp2855_ioctl()
562 struct tp2855 *tp2855 = (struct tp2855 *) data; in detect_thread_function() local
563 struct i2c_client *client = tp2855->client; in detect_thread_function()
566 tp2855->lost_video_status = true; in detect_thread_function()
568 if (tp2855->power_on) { in detect_thread_function()
573 if (tp2855->lost_video_status != lost_video) { in detect_thread_function()
579 tp2855->lost_video_status = lost_video; in detect_thread_function()
591 static int __maybe_unused detect_thread_start(struct tp2855 *tp2855) { in detect_thread_start() argument
593 struct i2c_client *client = tp2855->client; in detect_thread_start()
594 tp2855->detect_thread = kthread_create(detect_thread_function, in detect_thread_start()
595 tp2855, "tp2855_kthread"); in detect_thread_start()
596 if (IS_ERR(tp2855->detect_thread)) { in detect_thread_start()
598 ret = PTR_ERR(tp2855->detect_thread); in detect_thread_start()
599 tp2855->detect_thread = NULL; in detect_thread_start()
602 wake_up_process(tp2855->detect_thread); in detect_thread_start()
606 static int __maybe_unused detect_thread_stop(struct tp2855 *tp2855) { in detect_thread_stop() argument
607 if (tp2855->detect_thread) in detect_thread_stop()
608 kthread_stop(tp2855->detect_thread); in detect_thread_stop()
609 tp2855->detect_thread = NULL; in detect_thread_stop()
613 static int __tp2855_start_stream(struct tp2855 *tp2855) in __tp2855_start_stream() argument
617 struct i2c_client *client = tp2855->client; in __tp2855_start_stream()
619 if (tp2855->cur_mode->global_reg_list == common_setting_594M_1080p_25fps_regs) { in __tp2855_start_stream()
621 } else if (tp2855->cur_mode->global_reg_list == common_setting_297M_720p_25fps_regs) { in __tp2855_start_stream()
627 ret = tp2855_write_array(tp2855->client, in __tp2855_start_stream()
628 tp2855->cur_mode->global_reg_list, array_size); in __tp2855_start_stream()
634 detect_thread_start(tp2855); in __tp2855_start_stream()
639 static int __tp2855_stop_stream(struct tp2855 *tp2855) in __tp2855_stop_stream() argument
641 struct i2c_client *client = tp2855->client; in __tp2855_stop_stream()
645 detect_thread_stop(tp2855); in __tp2855_stop_stream()
652 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_stream() local
653 struct i2c_client *client = tp2855->client; in tp2855_stream()
656 tp2855->cur_mode->width, in tp2855_stream()
657 tp2855->cur_mode->height); in tp2855_stream()
659 mutex_lock(&tp2855->mutex); in tp2855_stream()
661 if (tp2855->streaming == on) in tp2855_stream()
665 __tp2855_start_stream(tp2855); in tp2855_stream()
667 __tp2855_stop_stream(tp2855); in tp2855_stream()
670 tp2855->streaming = on; in tp2855_stream()
673 mutex_unlock(&tp2855->mutex); in tp2855_stream()
680 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_power() local
681 struct i2c_client *client = tp2855->client; in tp2855_power()
684 mutex_lock(&tp2855->mutex); in tp2855_power()
687 if (tp2855->power_on == !!on) in tp2855_power()
698 tp2855->power_on = true; in tp2855_power()
701 tp2855->power_on = false; in tp2855_power()
705 mutex_unlock(&tp2855->mutex); in tp2855_power()
710 static int __tp2855_power_on(struct tp2855 *tp2855) in __tp2855_power_on() argument
713 struct device *dev = &tp2855->client->dev; in __tp2855_power_on()
717 if (!IS_ERR_OR_NULL(tp2855->pins_default)) { in __tp2855_power_on()
718 ret = pinctrl_select_state(tp2855->pinctrl, in __tp2855_power_on()
719 tp2855->pins_default); in __tp2855_power_on()
724 if (!IS_ERR(tp2855->power_gpio)) { in __tp2855_power_on()
725 gpiod_set_value_cansleep(tp2855->power_gpio, 1); in __tp2855_power_on()
731 ret = clk_set_rate(tp2855->xvclk, TP2855_XVCLK_FREQ); in __tp2855_power_on()
734 if (clk_get_rate(tp2855->xvclk) != TP2855_XVCLK_FREQ) in __tp2855_power_on()
736 ret = clk_prepare_enable(tp2855->xvclk); in __tp2855_power_on()
742 if (!IS_ERR(tp2855->reset_gpio)) { in __tp2855_power_on()
743 gpiod_set_value_cansleep(tp2855->reset_gpio, 1); in __tp2855_power_on()
745 gpiod_set_value_cansleep(tp2855->reset_gpio, 0); in __tp2855_power_on()
754 if (!IS_ERR(tp2855->reset_gpio)) in __tp2855_power_on()
755 gpiod_set_value_cansleep(tp2855->reset_gpio, 0); in __tp2855_power_on()
757 if (!IS_ERR_OR_NULL(tp2855->pins_sleep)) in __tp2855_power_on()
758 pinctrl_select_state(tp2855->pinctrl, tp2855->pins_sleep); in __tp2855_power_on()
763 static void __tp2855_power_off(struct tp2855 *tp2855) in __tp2855_power_off() argument
766 struct device *dev = &tp2855->client->dev; in __tp2855_power_off()
770 if (!IS_ERR(tp2855->reset_gpio)) in __tp2855_power_off()
771 gpiod_set_value_cansleep(tp2855->reset_gpio, 0); in __tp2855_power_off()
772 clk_disable_unprepare(tp2855->xvclk); in __tp2855_power_off()
774 if (!IS_ERR_OR_NULL(tp2855->pins_sleep)) { in __tp2855_power_off()
775 ret = pinctrl_select_state(tp2855->pinctrl, in __tp2855_power_off()
776 tp2855->pins_sleep); in __tp2855_power_off()
781 if (!IS_ERR(tp2855->power_gpio)) in __tp2855_power_off()
782 gpiod_set_value_cansleep(tp2855->power_gpio, 0); in __tp2855_power_off()
785 static int tp2855_initialize_controls(struct tp2855 *tp2855) in tp2855_initialize_controls() argument
792 handler = &tp2855->ctrl_handler; in tp2855_initialize_controls()
793 mode = tp2855->cur_mode; in tp2855_initialize_controls()
797 handler->lock = &tp2855->mutex; in tp2855_initialize_controls()
799 tp2855->link_freq = v4l2_ctrl_new_int_menu(handler, NULL, in tp2855_initialize_controls()
803 __v4l2_ctrl_s_ctrl(tp2855->link_freq, mode->mipi_freq_idx); in tp2855_initialize_controls()
807 tp2855->pixel_rate = v4l2_ctrl_new_std(handler, NULL, in tp2855_initialize_controls()
814 dev_err(&tp2855->client->dev, in tp2855_initialize_controls()
819 tp2855->subdev.ctrl_handler = handler; in tp2855_initialize_controls()
833 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_runtime_resume() local
835 return __tp2855_power_on(tp2855); in tp2855_runtime_resume()
842 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_runtime_suspend() local
844 __tp2855_power_off(tp2855); in tp2855_runtime_suspend()
852 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_open() local
857 dev_dbg(&tp2855->client->dev, "%s\n", __func__); in tp2855_open()
859 mutex_lock(&tp2855->mutex); in tp2855_open()
866 mutex_unlock(&tp2855->mutex); in tp2855_open()
921 struct tp2855 *tp2855; in tp2855_probe() local
931 tp2855 = devm_kzalloc(dev, sizeof(*tp2855), GFP_KERNEL); in tp2855_probe()
932 if (!tp2855) in tp2855_probe()
936 &tp2855->module_index); in tp2855_probe()
938 &tp2855->module_facing); in tp2855_probe()
940 &tp2855->module_name); in tp2855_probe()
942 &tp2855->len_name); in tp2855_probe()
948 tp2855->client = client; in tp2855_probe()
949 tp2855->cur_mode = &supported_modes[0]; in tp2855_probe()
951 tp2855->xvclk = devm_clk_get(dev, "xvclk"); in tp2855_probe()
952 if (IS_ERR(tp2855->xvclk)) { in tp2855_probe()
957 tp2855->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in tp2855_probe()
958 if (IS_ERR(tp2855->reset_gpio)) in tp2855_probe()
961 tp2855->power_gpio = devm_gpiod_get(dev, "power", GPIOD_OUT_LOW); in tp2855_probe()
962 if (IS_ERR(tp2855->power_gpio)) in tp2855_probe()
965 tp2855->pinctrl = devm_pinctrl_get(dev); in tp2855_probe()
966 if (!IS_ERR(tp2855->pinctrl)) { in tp2855_probe()
967 tp2855->pins_default = in tp2855_probe()
968 pinctrl_lookup_state(tp2855->pinctrl, in tp2855_probe()
970 if (IS_ERR(tp2855->pins_default)) in tp2855_probe()
973 tp2855->pins_sleep = in tp2855_probe()
974 pinctrl_lookup_state(tp2855->pinctrl, in tp2855_probe()
976 if (IS_ERR(tp2855->pins_sleep)) in tp2855_probe()
982 mutex_init(&tp2855->mutex); in tp2855_probe()
984 sd = &tp2855->subdev; in tp2855_probe()
986 ret = tp2855_initialize_controls(tp2855); in tp2855_probe()
992 ret = __tp2855_power_on(tp2855); in tp2855_probe()
1010 tp2855->pad.flags = MEDIA_PAD_FL_SOURCE; in tp2855_probe()
1012 ret = media_entity_pads_init(&sd->entity, 1, &tp2855->pad); in tp2855_probe()
1018 if (strcmp(tp2855->module_facing, "back") == 0) in tp2855_probe()
1024 tp2855->module_index, facing, in tp2855_probe()
1044 __tp2855_power_off(tp2855); in tp2855_probe()
1046 v4l2_ctrl_handler_free(&tp2855->ctrl_handler); in tp2855_probe()
1048 mutex_destroy(&tp2855->mutex); in tp2855_probe()
1056 struct tp2855 *tp2855 = to_tp2855(sd); in tp2855_remove() local
1062 v4l2_ctrl_handler_free(&tp2855->ctrl_handler); in tp2855_remove()
1063 mutex_destroy(&tp2855->mutex); in tp2855_remove()
1067 __tp2855_power_off(tp2855); in tp2855_remove()