Lines Matching refs:sc3338

127 struct sc3338 {  struct
163 #define to_sc3338(sd) container_of(sd, struct sc3338, subdev) argument
417 static int sc3338_set_gain_reg(struct sc3338 *sc3338, u32 gain) in sc3338_set_gain_reg() argument
419 struct i2c_client *client = sc3338->client; in sc3338_set_gain_reg()
474 ret = sc3338_write_reg(sc3338->client, in sc3338_set_gain_reg()
478 ret |= sc3338_write_reg(sc3338->client, in sc3338_set_gain_reg()
482 ret |= sc3338_write_reg(sc3338->client, in sc3338_set_gain_reg()
521 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_set_fmt() local
525 mutex_lock(&sc3338->mutex); in sc3338_set_fmt()
536 mutex_unlock(&sc3338->mutex); in sc3338_set_fmt()
540 sc3338->cur_mode = mode; in sc3338_set_fmt()
542 __v4l2_ctrl_modify_range(sc3338->hblank, h_blank, in sc3338_set_fmt()
545 __v4l2_ctrl_modify_range(sc3338->vblank, vblank_def, in sc3338_set_fmt()
548 sc3338->cur_fps = mode->max_fps; in sc3338_set_fmt()
551 mutex_unlock(&sc3338->mutex); in sc3338_set_fmt()
560 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_get_fmt() local
561 const struct sc3338_mode *mode = sc3338->cur_mode; in sc3338_get_fmt()
563 mutex_lock(&sc3338->mutex); in sc3338_get_fmt()
568 mutex_unlock(&sc3338->mutex); in sc3338_get_fmt()
582 mutex_unlock(&sc3338->mutex); in sc3338_get_fmt()
591 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_enum_mbus_code() local
595 code->code = sc3338->cur_mode->bus_fmt; in sc3338_enum_mbus_code()
618 static int sc3338_enable_test_pattern(struct sc3338 *sc3338, u32 pattern) in sc3338_enable_test_pattern() argument
623 ret = sc3338_read_reg(sc3338->client, SC3338_REG_TEST_PATTERN, in sc3338_enable_test_pattern()
630 ret |= sc3338_write_reg(sc3338->client, SC3338_REG_TEST_PATTERN, in sc3338_enable_test_pattern()
638 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_g_frame_interval() local
639 const struct sc3338_mode *mode = sc3338->cur_mode; in sc3338_g_frame_interval()
641 if (sc3338->streaming) in sc3338_g_frame_interval()
642 fi->interval = sc3338->cur_fps; in sc3338_g_frame_interval()
653 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_g_mbus_config() local
654 const struct sc3338_mode *mode = sc3338->cur_mode; in sc3338_g_mbus_config()
671 static void sc3338_get_module_inf(struct sc3338 *sc3338, in sc3338_get_module_inf() argument
676 strscpy(inf->base.module, sc3338->module_name, in sc3338_get_module_inf()
678 strscpy(inf->base.lens, sc3338->len_name, sizeof(inf->base.lens)); in sc3338_get_module_inf()
683 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_ioctl() local
691 sc3338_get_module_inf(sc3338, (struct rkmodule_inf *)arg); in sc3338_ioctl()
696 hdr->hdr_mode = sc3338->cur_mode->hdr_mode; in sc3338_ioctl()
700 w = sc3338->cur_mode->width; in sc3338_ioctl()
701 h = sc3338->cur_mode->height; in sc3338_ioctl()
706 sc3338->cur_mode = &supported_modes[i]; in sc3338_ioctl()
711 dev_err(&sc3338->client->dev, in sc3338_ioctl()
716 w = sc3338->cur_mode->hts_def - sc3338->cur_mode->width; in sc3338_ioctl()
717 h = sc3338->cur_mode->vts_def - sc3338->cur_mode->height; in sc3338_ioctl()
718 __v4l2_ctrl_modify_range(sc3338->hblank, w, w, 1, w); in sc3338_ioctl()
719 __v4l2_ctrl_modify_range(sc3338->vblank, h, in sc3338_ioctl()
720 SC3338_VTS_MAX - sc3338->cur_mode->height, 1, h); in sc3338_ioctl()
721 sc3338->cur_fps = sc3338->cur_mode->max_fps; in sc3338_ioctl()
731 ret = sc3338_write_reg(sc3338->client, SC3338_REG_CTRL_MODE, in sc3338_ioctl()
734 ret = sc3338_write_reg(sc3338->client, SC3338_REG_CTRL_MODE, in sc3338_ioctl()
829 static int __sc3338_start_stream(struct sc3338 *sc3338) in __sc3338_start_stream() argument
833 if (!sc3338->is_thunderboot) { in __sc3338_start_stream()
834 ret = sc3338_write_array(sc3338->client, sc3338->cur_mode->reg_list); in __sc3338_start_stream()
838 ret = __v4l2_ctrl_handler_setup(&sc3338->ctrl_handler); in __sc3338_start_stream()
841 if (sc3338->has_init_exp && sc3338->cur_mode->hdr_mode != NO_HDR) { in __sc3338_start_stream()
842 ret = sc3338_ioctl(&sc3338->subdev, PREISP_CMD_SET_HDRAE_EXP, in __sc3338_start_stream()
843 &sc3338->init_hdrae_exp); in __sc3338_start_stream()
845 dev_err(&sc3338->client->dev, in __sc3338_start_stream()
851 return sc3338_write_reg(sc3338->client, SC3338_REG_CTRL_MODE, in __sc3338_start_stream()
855 static int __sc3338_stop_stream(struct sc3338 *sc3338) in __sc3338_stop_stream() argument
857 sc3338->has_init_exp = false; in __sc3338_stop_stream()
858 if (sc3338->is_thunderboot) { in __sc3338_stop_stream()
859 sc3338->is_first_streamoff = true; in __sc3338_stop_stream()
860 pm_runtime_put(&sc3338->client->dev); in __sc3338_stop_stream()
862 return sc3338_write_reg(sc3338->client, SC3338_REG_CTRL_MODE, in __sc3338_stop_stream()
866 static int __sc3338_power_on(struct sc3338 *sc3338);
869 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_s_stream() local
870 struct i2c_client *client = sc3338->client; in sc3338_s_stream()
873 mutex_lock(&sc3338->mutex); in sc3338_s_stream()
875 if (on == sc3338->streaming) in sc3338_s_stream()
878 if (sc3338->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) { in sc3338_s_stream()
879 sc3338->is_thunderboot = false; in sc3338_s_stream()
880 __sc3338_power_on(sc3338); in sc3338_s_stream()
887 ret = __sc3338_start_stream(sc3338); in sc3338_s_stream()
894 __sc3338_stop_stream(sc3338); in sc3338_s_stream()
898 sc3338->streaming = on; in sc3338_s_stream()
900 mutex_unlock(&sc3338->mutex); in sc3338_s_stream()
906 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_s_power() local
907 struct i2c_client *client = sc3338->client; in sc3338_s_power()
910 mutex_lock(&sc3338->mutex); in sc3338_s_power()
913 if (sc3338->power_on == !!on) in sc3338_s_power()
923 if (!sc3338->is_thunderboot) { in sc3338_s_power()
924 ret = sc3338_write_array(sc3338->client, sc3338_global_regs); in sc3338_s_power()
932 sc3338->power_on = true; in sc3338_s_power()
935 sc3338->power_on = false; in sc3338_s_power()
939 mutex_unlock(&sc3338->mutex); in sc3338_s_power()
950 static int __sc3338_power_on(struct sc3338 *sc3338) in __sc3338_power_on() argument
954 struct device *dev = &sc3338->client->dev; in __sc3338_power_on()
956 if (!IS_ERR_OR_NULL(sc3338->pins_default)) { in __sc3338_power_on()
957 ret = pinctrl_select_state(sc3338->pinctrl, in __sc3338_power_on()
958 sc3338->pins_default); in __sc3338_power_on()
962 ret = clk_set_rate(sc3338->xvclk, SC3338_XVCLK_FREQ); in __sc3338_power_on()
965 if (clk_get_rate(sc3338->xvclk) != SC3338_XVCLK_FREQ) in __sc3338_power_on()
967 ret = clk_prepare_enable(sc3338->xvclk); in __sc3338_power_on()
973 if (sc3338->is_thunderboot) in __sc3338_power_on()
976 if (!IS_ERR(sc3338->reset_gpio)) in __sc3338_power_on()
977 gpiod_set_value_cansleep(sc3338->reset_gpio, 0); in __sc3338_power_on()
979 ret = regulator_bulk_enable(SC3338_NUM_SUPPLIES, sc3338->supplies); in __sc3338_power_on()
985 if (!IS_ERR(sc3338->reset_gpio)) in __sc3338_power_on()
986 gpiod_set_value_cansleep(sc3338->reset_gpio, 1); in __sc3338_power_on()
990 if (!IS_ERR(sc3338->pwdn_gpio)) in __sc3338_power_on()
991 gpiod_set_value_cansleep(sc3338->pwdn_gpio, 1); in __sc3338_power_on()
993 if (!IS_ERR(sc3338->reset_gpio)) in __sc3338_power_on()
1005 clk_disable_unprepare(sc3338->xvclk); in __sc3338_power_on()
1010 static void __sc3338_power_off(struct sc3338 *sc3338) in __sc3338_power_off() argument
1013 struct device *dev = &sc3338->client->dev; in __sc3338_power_off()
1015 clk_disable_unprepare(sc3338->xvclk); in __sc3338_power_off()
1016 if (sc3338->is_thunderboot) { in __sc3338_power_off()
1017 if (sc3338->is_first_streamoff) { in __sc3338_power_off()
1018 sc3338->is_thunderboot = false; in __sc3338_power_off()
1019 sc3338->is_first_streamoff = false; in __sc3338_power_off()
1025 if (!IS_ERR(sc3338->pwdn_gpio)) in __sc3338_power_off()
1026 gpiod_set_value_cansleep(sc3338->pwdn_gpio, 0); in __sc3338_power_off()
1027 clk_disable_unprepare(sc3338->xvclk); in __sc3338_power_off()
1028 if (!IS_ERR(sc3338->reset_gpio)) in __sc3338_power_off()
1029 gpiod_set_value_cansleep(sc3338->reset_gpio, 0); in __sc3338_power_off()
1030 if (!IS_ERR_OR_NULL(sc3338->pins_sleep)) { in __sc3338_power_off()
1031 ret = pinctrl_select_state(sc3338->pinctrl, in __sc3338_power_off()
1032 sc3338->pins_sleep); in __sc3338_power_off()
1036 regulator_bulk_disable(SC3338_NUM_SUPPLIES, sc3338->supplies); in __sc3338_power_off()
1043 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_runtime_resume() local
1045 return __sc3338_power_on(sc3338); in sc3338_runtime_resume()
1052 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_runtime_suspend() local
1054 __sc3338_power_off(sc3338); in sc3338_runtime_suspend()
1062 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_open() local
1067 mutex_lock(&sc3338->mutex); in sc3338_open()
1074 mutex_unlock(&sc3338->mutex); in sc3338_open()
1135 static void sc3338_modify_fps_info(struct sc3338 *sc3338) in sc3338_modify_fps_info() argument
1137 const struct sc3338_mode *mode = sc3338->cur_mode; in sc3338_modify_fps_info()
1139 sc3338->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def / in sc3338_modify_fps_info()
1140 sc3338->cur_vts; in sc3338_modify_fps_info()
1145 struct sc3338 *sc3338 = container_of(ctrl->handler, in sc3338_set_ctrl() local
1146 struct sc3338, ctrl_handler); in sc3338_set_ctrl()
1147 struct i2c_client *client = sc3338->client; in sc3338_set_ctrl()
1156 max = sc3338->cur_mode->height + ctrl->val - 8; in sc3338_set_ctrl()
1157 __v4l2_ctrl_modify_range(sc3338->exposure, in sc3338_set_ctrl()
1158 sc3338->exposure->minimum, max, in sc3338_set_ctrl()
1159 sc3338->exposure->step, in sc3338_set_ctrl()
1160 sc3338->exposure->default_value); in sc3338_set_ctrl()
1170 if (sc3338->cur_mode->hdr_mode == NO_HDR) { in sc3338_set_ctrl()
1173 ret = sc3338_write_reg(sc3338->client, in sc3338_set_ctrl()
1177 ret |= sc3338_write_reg(sc3338->client, in sc3338_set_ctrl()
1181 ret |= sc3338_write_reg(sc3338->client, in sc3338_set_ctrl()
1189 if (sc3338->cur_mode->hdr_mode == NO_HDR) in sc3338_set_ctrl()
1190 ret = sc3338_set_gain_reg(sc3338, ctrl->val); in sc3338_set_ctrl()
1194 ret = sc3338_write_reg(sc3338->client, in sc3338_set_ctrl()
1197 (ctrl->val + sc3338->cur_mode->height) in sc3338_set_ctrl()
1199 ret |= sc3338_write_reg(sc3338->client, in sc3338_set_ctrl()
1202 (ctrl->val + sc3338->cur_mode->height) in sc3338_set_ctrl()
1204 sc3338->cur_vts = ctrl->val + sc3338->cur_mode->height; in sc3338_set_ctrl()
1205 sc3338_modify_fps_info(sc3338); in sc3338_set_ctrl()
1208 ret = sc3338_enable_test_pattern(sc3338, ctrl->val); in sc3338_set_ctrl()
1211 ret = sc3338_read_reg(sc3338->client, SC3338_FLIP_MIRROR_REG, in sc3338_set_ctrl()
1213 ret |= sc3338_write_reg(sc3338->client, SC3338_FLIP_MIRROR_REG, in sc3338_set_ctrl()
1218 ret = sc3338_read_reg(sc3338->client, SC3338_FLIP_MIRROR_REG, in sc3338_set_ctrl()
1220 ret |= sc3338_write_reg(sc3338->client, SC3338_FLIP_MIRROR_REG, in sc3338_set_ctrl()
1239 static int sc3338_initialize_controls(struct sc3338 *sc3338) in sc3338_initialize_controls() argument
1248 handler = &sc3338->ctrl_handler; in sc3338_initialize_controls()
1249 mode = sc3338->cur_mode; in sc3338_initialize_controls()
1253 handler->lock = &sc3338->mutex; in sc3338_initialize_controls()
1264 sc3338->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in sc3338_initialize_controls()
1266 if (sc3338->hblank) in sc3338_initialize_controls()
1267 sc3338->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in sc3338_initialize_controls()
1269 sc3338->vblank = v4l2_ctrl_new_std(handler, &sc3338_ctrl_ops, in sc3338_initialize_controls()
1274 sc3338->exposure = v4l2_ctrl_new_std(handler, &sc3338_ctrl_ops, in sc3338_initialize_controls()
1278 sc3338->anal_gain = v4l2_ctrl_new_std(handler, &sc3338_ctrl_ops, in sc3338_initialize_controls()
1282 sc3338->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in sc3338_initialize_controls()
1293 dev_err(&sc3338->client->dev, in sc3338_initialize_controls()
1298 sc3338->subdev.ctrl_handler = handler; in sc3338_initialize_controls()
1299 sc3338->has_init_exp = false; in sc3338_initialize_controls()
1300 sc3338->cur_fps = mode->max_fps; in sc3338_initialize_controls()
1310 static int sc3338_check_sensor_id(struct sc3338 *sc3338, in sc3338_check_sensor_id() argument
1313 struct device *dev = &sc3338->client->dev; in sc3338_check_sensor_id()
1317 if (sc3338->is_thunderboot) { in sc3338_check_sensor_id()
1334 static int sc3338_configure_regulators(struct sc3338 *sc3338) in sc3338_configure_regulators() argument
1339 sc3338->supplies[i].supply = sc3338_supply_names[i]; in sc3338_configure_regulators()
1341 return devm_regulator_bulk_get(&sc3338->client->dev, in sc3338_configure_regulators()
1343 sc3338->supplies); in sc3338_configure_regulators()
1351 struct sc3338 *sc3338; in sc3338_probe() local
1362 sc3338 = devm_kzalloc(dev, sizeof(*sc3338), GFP_KERNEL); in sc3338_probe()
1363 if (!sc3338) in sc3338_probe()
1367 &sc3338->module_index); in sc3338_probe()
1369 &sc3338->module_facing); in sc3338_probe()
1371 &sc3338->module_name); in sc3338_probe()
1373 &sc3338->len_name); in sc3338_probe()
1379 sc3338->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP); in sc3338_probe()
1381 sc3338->client = client; in sc3338_probe()
1384 sc3338->cur_mode = &supported_modes[i]; in sc3338_probe()
1389 sc3338->cur_mode = &supported_modes[0]; in sc3338_probe()
1391 sc3338->xvclk = devm_clk_get(dev, "xvclk"); in sc3338_probe()
1392 if (IS_ERR(sc3338->xvclk)) { in sc3338_probe()
1397 sc3338->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); in sc3338_probe()
1398 if (IS_ERR(sc3338->reset_gpio)) in sc3338_probe()
1401 sc3338->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS); in sc3338_probe()
1402 if (IS_ERR(sc3338->pwdn_gpio)) in sc3338_probe()
1405 sc3338->pinctrl = devm_pinctrl_get(dev); in sc3338_probe()
1406 if (!IS_ERR(sc3338->pinctrl)) { in sc3338_probe()
1407 sc3338->pins_default = in sc3338_probe()
1408 pinctrl_lookup_state(sc3338->pinctrl, in sc3338_probe()
1410 if (IS_ERR(sc3338->pins_default)) in sc3338_probe()
1413 sc3338->pins_sleep = in sc3338_probe()
1414 pinctrl_lookup_state(sc3338->pinctrl, in sc3338_probe()
1416 if (IS_ERR(sc3338->pins_sleep)) in sc3338_probe()
1422 ret = sc3338_configure_regulators(sc3338); in sc3338_probe()
1428 mutex_init(&sc3338->mutex); in sc3338_probe()
1430 sd = &sc3338->subdev; in sc3338_probe()
1432 ret = sc3338_initialize_controls(sc3338); in sc3338_probe()
1436 ret = __sc3338_power_on(sc3338); in sc3338_probe()
1440 ret = sc3338_check_sensor_id(sc3338, client); in sc3338_probe()
1450 sc3338->pad.flags = MEDIA_PAD_FL_SOURCE; in sc3338_probe()
1452 ret = media_entity_pads_init(&sd->entity, 1, &sc3338->pad); in sc3338_probe()
1458 if (strcmp(sc3338->module_facing, "back") == 0) in sc3338_probe()
1464 sc3338->module_index, facing, in sc3338_probe()
1474 if (sc3338->is_thunderboot) in sc3338_probe()
1486 __sc3338_power_off(sc3338); in sc3338_probe()
1488 v4l2_ctrl_handler_free(&sc3338->ctrl_handler); in sc3338_probe()
1490 mutex_destroy(&sc3338->mutex); in sc3338_probe()
1498 struct sc3338 *sc3338 = to_sc3338(sd); in sc3338_remove() local
1504 v4l2_ctrl_handler_free(&sc3338->ctrl_handler); in sc3338_remove()
1505 mutex_destroy(&sc3338->mutex); in sc3338_remove()
1509 __sc3338_power_off(sc3338); in sc3338_remove()