Lines Matching refs:sc2239
105 struct sc2239 { struct
133 #define to_sc2239(sd) container_of(sd, struct sc2239, subdev) argument
384 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_set_fmt() local
388 mutex_lock(&sc2239->mutex); in sc2239_set_fmt()
399 mutex_unlock(&sc2239->mutex); in sc2239_set_fmt()
403 sc2239->cur_mode = mode; in sc2239_set_fmt()
405 __v4l2_ctrl_modify_range(sc2239->hblank, h_blank, in sc2239_set_fmt()
408 __v4l2_ctrl_modify_range(sc2239->vblank, vblank_def, in sc2239_set_fmt()
411 sc2239->cur_fps = mode->max_fps; in sc2239_set_fmt()
412 sc2239->cur_vts = mode->vts_def; in sc2239_set_fmt()
415 mutex_unlock(&sc2239->mutex); in sc2239_set_fmt()
424 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_get_fmt() local
425 const struct sc2239_mode *mode = sc2239->cur_mode; in sc2239_get_fmt()
427 mutex_lock(&sc2239->mutex); in sc2239_get_fmt()
432 mutex_unlock(&sc2239->mutex); in sc2239_get_fmt()
441 mutex_unlock(&sc2239->mutex); in sc2239_get_fmt()
475 static int sc2239_enable_test_pattern(struct sc2239 *sc2239, u32 pattern) in sc2239_enable_test_pattern() argument
480 ret = sc2239_read_reg(sc2239->client, SC2239_REG_TEST_PATTERN, in sc2239_enable_test_pattern()
487 ret |= sc2239_write_reg(sc2239->client, SC2239_REG_TEST_PATTERN, in sc2239_enable_test_pattern()
492 static void sc2239_get_module_inf(struct sc2239 *sc2239, in sc2239_get_module_inf() argument
497 strlcpy(inf->base.module, sc2239->module_name, in sc2239_get_module_inf()
499 strlcpy(inf->base.lens, sc2239->len_name, sizeof(inf->base.lens)); in sc2239_get_module_inf()
504 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_ioctl() local
510 sc2239_get_module_inf(sc2239, (struct rkmodule_inf *)arg); in sc2239_ioctl()
516 ret = sc2239_write_reg(sc2239->client, SC2239_REG_CTRL_MODE, in sc2239_ioctl()
519 ret = sc2239_write_reg(sc2239->client, SC2239_REG_CTRL_MODE, in sc2239_ioctl()
586 static int sc2239_set_ctrl_gain(struct sc2239 *sc2239, u32 a_gain) in sc2239_set_ctrl_gain() argument
592 if ( a_gain != sc2239->old_gain) { in sc2239_set_ctrl_gain()
623 ret = sc2239_write_reg(sc2239->client, 0x3634, in sc2239_set_ctrl_gain()
625 ret |= sc2239_write_reg(sc2239->client, in sc2239_set_ctrl_gain()
629 ret |= sc2239_write_reg(sc2239->client, in sc2239_set_ctrl_gain()
633 sc2239->old_gain = a_gain; in sc2239_set_ctrl_gain()
638 static int __sc2239_start_stream(struct sc2239 *sc2239) in __sc2239_start_stream() argument
642 ret = sc2239_write_array(sc2239->client, sc2239->cur_mode->reg_list); in __sc2239_start_stream()
647 mutex_unlock(&sc2239->mutex); in __sc2239_start_stream()
648 ret = v4l2_ctrl_handler_setup(&sc2239->ctrl_handler); in __sc2239_start_stream()
649 mutex_lock(&sc2239->mutex); in __sc2239_start_stream()
653 return sc2239_write_reg(sc2239->client, SC2239_REG_CTRL_MODE, in __sc2239_start_stream()
657 static int __sc2239_stop_stream(struct sc2239 *sc2239) in __sc2239_stop_stream() argument
659 return sc2239_write_reg(sc2239->client, SC2239_REG_CTRL_MODE, in __sc2239_stop_stream()
665 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_s_stream() local
666 struct i2c_client *client = sc2239->client; in sc2239_s_stream()
670 sc2239->cur_mode->width, in sc2239_s_stream()
671 sc2239->cur_mode->height, in sc2239_s_stream()
672 DIV_ROUND_CLOSEST(sc2239->cur_mode->max_fps.denominator, in sc2239_s_stream()
673 sc2239->cur_mode->max_fps.numerator)); in sc2239_s_stream()
675 mutex_lock(&sc2239->mutex); in sc2239_s_stream()
677 if (on == sc2239->streaming) in sc2239_s_stream()
687 ret = __sc2239_start_stream(sc2239); in sc2239_s_stream()
694 __sc2239_stop_stream(sc2239); in sc2239_s_stream()
698 sc2239->streaming = on; in sc2239_s_stream()
701 mutex_unlock(&sc2239->mutex); in sc2239_s_stream()
709 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_g_frame_interval() local
710 const struct sc2239_mode *mode = sc2239->cur_mode; in sc2239_g_frame_interval()
712 if (sc2239->streaming) in sc2239_g_frame_interval()
713 fi->interval = sc2239->cur_fps; in sc2239_g_frame_interval()
722 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_s_power() local
723 struct i2c_client *client = sc2239->client; in sc2239_s_power()
726 mutex_lock(&sc2239->mutex); in sc2239_s_power()
729 if (sc2239->power_on == !!on) in sc2239_s_power()
738 ret = sc2239_write_array(sc2239->client, sc2239_global_regs); in sc2239_s_power()
744 sc2239->power_on = true; in sc2239_s_power()
747 sc2239->power_on = false; in sc2239_s_power()
751 mutex_unlock(&sc2239->mutex); in sc2239_s_power()
762 static int __sc2239_power_on(struct sc2239 *sc2239) in __sc2239_power_on() argument
766 struct device *dev = &sc2239->client->dev; in __sc2239_power_on()
768 ret = clk_set_rate(sc2239->xvclk, SC2239_XVCLK_FREQ); in __sc2239_power_on()
771 if (clk_get_rate(sc2239->xvclk) != SC2239_XVCLK_FREQ) in __sc2239_power_on()
773 ret = clk_prepare_enable(sc2239->xvclk); in __sc2239_power_on()
778 if (!IS_ERR(sc2239->reset_gpio)) in __sc2239_power_on()
779 gpiod_set_value_cansleep(sc2239->reset_gpio, 0); in __sc2239_power_on()
781 ret = regulator_bulk_enable(SC2239_NUM_SUPPLIES, sc2239->supplies); in __sc2239_power_on()
787 if (!IS_ERR(sc2239->reset_gpio)) in __sc2239_power_on()
788 gpiod_set_value_cansleep(sc2239->reset_gpio, 1); in __sc2239_power_on()
790 if (!IS_ERR(sc2239->pwdn_gpio)) in __sc2239_power_on()
791 gpiod_set_value_cansleep(sc2239->pwdn_gpio, 1); in __sc2239_power_on()
800 clk_disable_unprepare(sc2239->xvclk); in __sc2239_power_on()
805 static void __sc2239_power_off(struct sc2239 *sc2239) in __sc2239_power_off() argument
807 if (!IS_ERR(sc2239->pwdn_gpio)) in __sc2239_power_off()
808 gpiod_set_value_cansleep(sc2239->pwdn_gpio, 0); in __sc2239_power_off()
809 clk_disable_unprepare(sc2239->xvclk); in __sc2239_power_off()
810 if (!IS_ERR(sc2239->reset_gpio)) in __sc2239_power_off()
811 gpiod_set_value_cansleep(sc2239->reset_gpio, 0); in __sc2239_power_off()
813 regulator_bulk_disable(SC2239_NUM_SUPPLIES, sc2239->supplies); in __sc2239_power_off()
820 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_runtime_resume() local
822 return __sc2239_power_on(sc2239); in sc2239_runtime_resume()
829 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_runtime_suspend() local
831 __sc2239_power_off(sc2239); in sc2239_runtime_suspend()
839 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_open() local
844 mutex_lock(&sc2239->mutex); in sc2239_open()
851 mutex_unlock(&sc2239->mutex); in sc2239_open()
925 static void sc2239_modify_fps_info(struct sc2239 *sc2239) in sc2239_modify_fps_info() argument
927 const struct sc2239_mode *mode = sc2239->cur_mode; in sc2239_modify_fps_info()
929 sc2239->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def / in sc2239_modify_fps_info()
930 sc2239->cur_vts; in sc2239_modify_fps_info()
935 struct sc2239 *sc2239 = container_of(ctrl->handler, in sc2239_set_ctrl() local
936 struct sc2239, ctrl_handler); in sc2239_set_ctrl()
937 struct i2c_client *client = sc2239->client; in sc2239_set_ctrl()
947 max = sc2239->cur_mode->height + ctrl->val - 4; in sc2239_set_ctrl()
948 __v4l2_ctrl_modify_range(sc2239->exposure, in sc2239_set_ctrl()
949 sc2239->exposure->minimum, max, in sc2239_set_ctrl()
950 sc2239->exposure->step, in sc2239_set_ctrl()
951 sc2239->exposure->default_value); in sc2239_set_ctrl()
961 ret = sc2239_write_reg(sc2239->client, SC2239_REG_EXPOSURE, in sc2239_set_ctrl()
967 ret = sc2239_set_ctrl_gain(sc2239, ctrl->val); in sc2239_set_ctrl()
972 ret = sc2239_write_reg(sc2239->client, SC2239_REG_VTS, in sc2239_set_ctrl()
974 ctrl->val + sc2239->cur_mode->height); in sc2239_set_ctrl()
976 sc2239->cur_vts = ctrl->val + sc2239->cur_mode->height; in sc2239_set_ctrl()
977 sc2239_modify_fps_info(sc2239); in sc2239_set_ctrl()
980 ret = sc2239_enable_test_pattern(sc2239, ctrl->val); in sc2239_set_ctrl()
997 static int sc2239_initialize_controls(struct sc2239 *sc2239) in sc2239_initialize_controls() argument
1006 handler = &sc2239->ctrl_handler; in sc2239_initialize_controls()
1007 mode = sc2239->cur_mode; in sc2239_initialize_controls()
1011 handler->lock = &sc2239->mutex; in sc2239_initialize_controls()
1022 sc2239->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in sc2239_initialize_controls()
1024 if (sc2239->hblank) in sc2239_initialize_controls()
1025 sc2239->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in sc2239_initialize_controls()
1028 sc2239->vblank = v4l2_ctrl_new_std(handler, &sc2239_ctrl_ops, in sc2239_initialize_controls()
1034 sc2239->exposure = v4l2_ctrl_new_std(handler, &sc2239_ctrl_ops, in sc2239_initialize_controls()
1039 sc2239->anal_gain = v4l2_ctrl_new_std(handler, &sc2239_ctrl_ops, in sc2239_initialize_controls()
1044 sc2239->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in sc2239_initialize_controls()
1051 dev_err(&sc2239->client->dev, in sc2239_initialize_controls()
1056 sc2239->subdev.ctrl_handler = handler; in sc2239_initialize_controls()
1057 sc2239->old_gain = ANALOG_GAIN_DEFAULT; in sc2239_initialize_controls()
1058 sc2239->cur_fps = mode->max_fps; in sc2239_initialize_controls()
1059 sc2239->cur_vts = mode->vts_def; in sc2239_initialize_controls()
1069 static int sc2239_check_sensor_id(struct sc2239 *sc2239, in sc2239_check_sensor_id() argument
1072 struct device *dev = &sc2239->client->dev; in sc2239_check_sensor_id()
1088 static int sc2239_configure_regulators(struct sc2239 *sc2239) in sc2239_configure_regulators() argument
1093 sc2239->supplies[i].supply = sc2239_supply_names[i]; in sc2239_configure_regulators()
1095 return devm_regulator_bulk_get(&sc2239->client->dev, in sc2239_configure_regulators()
1097 sc2239->supplies); in sc2239_configure_regulators()
1105 struct sc2239 *sc2239; in sc2239_probe() local
1115 sc2239 = devm_kzalloc(dev, sizeof(*sc2239), GFP_KERNEL); in sc2239_probe()
1116 if (!sc2239) in sc2239_probe()
1120 &sc2239->module_index); in sc2239_probe()
1122 &sc2239->module_facing); in sc2239_probe()
1124 &sc2239->module_name); in sc2239_probe()
1126 &sc2239->len_name); in sc2239_probe()
1132 sc2239->client = client; in sc2239_probe()
1133 sc2239->cur_mode = &supported_modes[0]; in sc2239_probe()
1135 sc2239->xvclk = devm_clk_get(dev, "xvclk"); in sc2239_probe()
1136 if (IS_ERR(sc2239->xvclk)) { in sc2239_probe()
1141 sc2239->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in sc2239_probe()
1142 if (IS_ERR(sc2239->reset_gpio)) in sc2239_probe()
1145 sc2239->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in sc2239_probe()
1146 if (IS_ERR(sc2239->pwdn_gpio)) in sc2239_probe()
1148 ret = sc2239_configure_regulators(sc2239); in sc2239_probe()
1154 mutex_init(&sc2239->mutex); in sc2239_probe()
1156 sd = &sc2239->subdev; in sc2239_probe()
1158 ret = sc2239_initialize_controls(sc2239); in sc2239_probe()
1162 ret = __sc2239_power_on(sc2239); in sc2239_probe()
1166 ret = sc2239_check_sensor_id(sc2239, client); in sc2239_probe()
1176 sc2239->pad.flags = MEDIA_PAD_FL_SOURCE; in sc2239_probe()
1178 ret = media_entity_pads_init(&sd->entity, 1, &sc2239->pad); in sc2239_probe()
1184 if (strcmp(sc2239->module_facing, "back") == 0) in sc2239_probe()
1190 sc2239->module_index, facing, in sc2239_probe()
1209 __sc2239_power_off(sc2239); in sc2239_probe()
1211 v4l2_ctrl_handler_free(&sc2239->ctrl_handler); in sc2239_probe()
1213 mutex_destroy(&sc2239->mutex); in sc2239_probe()
1221 struct sc2239 *sc2239 = to_sc2239(sd); in sc2239_remove() local
1227 v4l2_ctrl_handler_free(&sc2239->ctrl_handler); in sc2239_remove()
1228 mutex_destroy(&sc2239->mutex); in sc2239_remove()
1232 __sc2239_power_off(sc2239); in sc2239_remove()