Lines Matching refs:sc4336
128 struct sc4336 { struct
162 #define to_sc4336(sd) container_of(sd, struct sc4336, subdev) argument
425 static int sc4336_set_gain_reg(struct sc4336 *sc4336, u32 gain) in sc4336_set_gain_reg() argument
480 ret = sc4336_write_reg(sc4336->client, in sc4336_set_gain_reg()
484 ret |= sc4336_write_reg(sc4336->client, in sc4336_set_gain_reg()
488 ret |= sc4336_write_reg(sc4336->client, in sc4336_set_gain_reg()
527 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_set_fmt() local
531 mutex_lock(&sc4336->mutex); in sc4336_set_fmt()
542 mutex_unlock(&sc4336->mutex); in sc4336_set_fmt()
546 sc4336->cur_mode = mode; in sc4336_set_fmt()
548 __v4l2_ctrl_modify_range(sc4336->hblank, h_blank, in sc4336_set_fmt()
551 __v4l2_ctrl_modify_range(sc4336->vblank, vblank_def, in sc4336_set_fmt()
554 sc4336->cur_fps = mode->max_fps; in sc4336_set_fmt()
557 mutex_unlock(&sc4336->mutex); in sc4336_set_fmt()
566 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_get_fmt() local
567 const struct sc4336_mode *mode = sc4336->cur_mode; in sc4336_get_fmt()
569 mutex_lock(&sc4336->mutex); in sc4336_get_fmt()
574 mutex_unlock(&sc4336->mutex); in sc4336_get_fmt()
588 mutex_unlock(&sc4336->mutex); in sc4336_get_fmt()
597 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_enum_mbus_code() local
601 code->code = sc4336->cur_mode->bus_fmt; in sc4336_enum_mbus_code()
624 static int sc4336_enable_test_pattern(struct sc4336 *sc4336, u32 pattern) in sc4336_enable_test_pattern() argument
629 ret = sc4336_read_reg(sc4336->client, SC4336_REG_TEST_PATTERN, in sc4336_enable_test_pattern()
636 ret |= sc4336_write_reg(sc4336->client, SC4336_REG_TEST_PATTERN, in sc4336_enable_test_pattern()
644 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_g_frame_interval() local
645 const struct sc4336_mode *mode = sc4336->cur_mode; in sc4336_g_frame_interval()
647 if (sc4336->streaming) in sc4336_g_frame_interval()
648 fi->interval = sc4336->cur_fps; in sc4336_g_frame_interval()
659 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_g_mbus_config() local
660 const struct sc4336_mode *mode = sc4336->cur_mode; in sc4336_g_mbus_config()
676 static void sc4336_get_module_inf(struct sc4336 *sc4336, in sc4336_get_module_inf() argument
681 strscpy(inf->base.module, sc4336->module_name, in sc4336_get_module_inf()
683 strscpy(inf->base.lens, sc4336->len_name, sizeof(inf->base.lens)); in sc4336_get_module_inf()
688 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_ioctl() local
696 sc4336_get_module_inf(sc4336, (struct rkmodule_inf *)arg); in sc4336_ioctl()
701 hdr->hdr_mode = sc4336->cur_mode->hdr_mode; in sc4336_ioctl()
705 w = sc4336->cur_mode->width; in sc4336_ioctl()
706 h = sc4336->cur_mode->height; in sc4336_ioctl()
711 sc4336->cur_mode = &supported_modes[i]; in sc4336_ioctl()
716 dev_err(&sc4336->client->dev, in sc4336_ioctl()
721 w = sc4336->cur_mode->hts_def - sc4336->cur_mode->width; in sc4336_ioctl()
722 h = sc4336->cur_mode->vts_def - sc4336->cur_mode->height; in sc4336_ioctl()
723 __v4l2_ctrl_modify_range(sc4336->hblank, w, w, 1, w); in sc4336_ioctl()
724 __v4l2_ctrl_modify_range(sc4336->vblank, h, in sc4336_ioctl()
725 SC4336_VTS_MAX - sc4336->cur_mode->height, 1, h); in sc4336_ioctl()
735 ret = sc4336_write_reg(sc4336->client, SC4336_REG_CTRL_MODE, in sc4336_ioctl()
738 ret = sc4336_write_reg(sc4336->client, SC4336_REG_CTRL_MODE, in sc4336_ioctl()
833 static int __sc4336_start_stream(struct sc4336 *sc4336) in __sc4336_start_stream() argument
836 if (!sc4336->is_thunderboot) { in __sc4336_start_stream()
837 ret = sc4336_write_array(sc4336->client, sc4336->cur_mode->reg_list); in __sc4336_start_stream()
842 ret = __v4l2_ctrl_handler_setup(&sc4336->ctrl_handler); in __sc4336_start_stream()
847 return sc4336_write_reg(sc4336->client, SC4336_REG_CTRL_MODE, in __sc4336_start_stream()
851 static int __sc4336_stop_stream(struct sc4336 *sc4336) in __sc4336_stop_stream() argument
853 if (sc4336->is_thunderboot) { in __sc4336_stop_stream()
854 sc4336->is_first_streamoff = true; in __sc4336_stop_stream()
855 pm_runtime_put(&sc4336->client->dev); in __sc4336_stop_stream()
857 return sc4336_write_reg(sc4336->client, SC4336_REG_CTRL_MODE, in __sc4336_stop_stream()
861 static int __sc4336_power_on(struct sc4336 *sc4336);
864 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_s_stream() local
865 struct i2c_client *client = sc4336->client; in sc4336_s_stream()
868 mutex_lock(&sc4336->mutex); in sc4336_s_stream()
870 if (on == sc4336->streaming) in sc4336_s_stream()
874 if (sc4336->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) { in sc4336_s_stream()
875 sc4336->is_thunderboot = false; in sc4336_s_stream()
876 __sc4336_power_on(sc4336); in sc4336_s_stream()
885 ret = __sc4336_start_stream(sc4336); in sc4336_s_stream()
892 __sc4336_stop_stream(sc4336); in sc4336_s_stream()
896 sc4336->streaming = on; in sc4336_s_stream()
899 mutex_unlock(&sc4336->mutex); in sc4336_s_stream()
906 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_s_power() local
907 struct i2c_client *client = sc4336->client; in sc4336_s_power()
910 mutex_lock(&sc4336->mutex); in sc4336_s_power()
913 if (sc4336->power_on == !!on) in sc4336_s_power()
923 if (!sc4336->is_thunderboot) { in sc4336_s_power()
924 ret = sc4336_write_array(sc4336->client, sc4336_global_regs); in sc4336_s_power()
932 sc4336->power_on = true; in sc4336_s_power()
935 sc4336->power_on = false; in sc4336_s_power()
939 mutex_unlock(&sc4336->mutex); in sc4336_s_power()
950 static int __sc4336_power_on(struct sc4336 *sc4336) in __sc4336_power_on() argument
954 struct device *dev = &sc4336->client->dev; in __sc4336_power_on()
956 if (!IS_ERR_OR_NULL(sc4336->pins_default)) { in __sc4336_power_on()
957 ret = pinctrl_select_state(sc4336->pinctrl, in __sc4336_power_on()
958 sc4336->pins_default); in __sc4336_power_on()
962 ret = clk_set_rate(sc4336->xvclk, SC4336_XVCLK_FREQ); in __sc4336_power_on()
965 if (clk_get_rate(sc4336->xvclk) != SC4336_XVCLK_FREQ) in __sc4336_power_on()
967 ret = clk_prepare_enable(sc4336->xvclk); in __sc4336_power_on()
972 if (sc4336->is_thunderboot) in __sc4336_power_on()
975 if (!IS_ERR(sc4336->reset_gpio)) in __sc4336_power_on()
976 gpiod_set_value_cansleep(sc4336->reset_gpio, 0); in __sc4336_power_on()
978 ret = regulator_bulk_enable(SC4336_NUM_SUPPLIES, sc4336->supplies); in __sc4336_power_on()
984 if (!IS_ERR(sc4336->reset_gpio)) in __sc4336_power_on()
985 gpiod_set_value_cansleep(sc4336->reset_gpio, 1); in __sc4336_power_on()
988 if (!IS_ERR(sc4336->pwdn_gpio)) in __sc4336_power_on()
989 gpiod_set_value_cansleep(sc4336->pwdn_gpio, 1); in __sc4336_power_on()
991 if (!IS_ERR(sc4336->reset_gpio)) in __sc4336_power_on()
1003 clk_disable_unprepare(sc4336->xvclk); in __sc4336_power_on()
1008 static void __sc4336_power_off(struct sc4336 *sc4336) in __sc4336_power_off() argument
1011 struct device *dev = &sc4336->client->dev; in __sc4336_power_off()
1013 clk_disable_unprepare(sc4336->xvclk); in __sc4336_power_off()
1014 if (sc4336->is_thunderboot) { in __sc4336_power_off()
1015 if (sc4336->is_first_streamoff) { in __sc4336_power_off()
1016 sc4336->is_thunderboot = false; in __sc4336_power_off()
1017 sc4336->is_first_streamoff = false; in __sc4336_power_off()
1023 if (!IS_ERR(sc4336->pwdn_gpio)) in __sc4336_power_off()
1024 gpiod_set_value_cansleep(sc4336->pwdn_gpio, 0); in __sc4336_power_off()
1025 if (!IS_ERR(sc4336->reset_gpio)) in __sc4336_power_off()
1026 gpiod_set_value_cansleep(sc4336->reset_gpio, 0); in __sc4336_power_off()
1027 if (!IS_ERR_OR_NULL(sc4336->pins_sleep)) { in __sc4336_power_off()
1028 ret = pinctrl_select_state(sc4336->pinctrl, in __sc4336_power_off()
1029 sc4336->pins_sleep); in __sc4336_power_off()
1033 regulator_bulk_disable(SC4336_NUM_SUPPLIES, sc4336->supplies); in __sc4336_power_off()
1040 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_runtime_resume() local
1042 return __sc4336_power_on(sc4336); in sc4336_runtime_resume()
1049 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_runtime_suspend() local
1051 __sc4336_power_off(sc4336); in sc4336_runtime_suspend()
1059 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_open() local
1064 mutex_lock(&sc4336->mutex); in sc4336_open()
1071 mutex_unlock(&sc4336->mutex); in sc4336_open()
1132 static void sc4336_modify_fps_info(struct sc4336 *sc4336) in sc4336_modify_fps_info() argument
1134 const struct sc4336_mode *mode = sc4336->cur_mode; in sc4336_modify_fps_info()
1136 sc4336->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def / in sc4336_modify_fps_info()
1137 sc4336->cur_vts; in sc4336_modify_fps_info()
1142 struct sc4336 *sc4336 = container_of(ctrl->handler, in sc4336_set_ctrl() local
1143 struct sc4336, ctrl_handler); in sc4336_set_ctrl()
1144 struct i2c_client *client = sc4336->client; in sc4336_set_ctrl()
1153 max = sc4336->cur_mode->height + ctrl->val - 8; in sc4336_set_ctrl()
1154 __v4l2_ctrl_modify_range(sc4336->exposure, in sc4336_set_ctrl()
1155 sc4336->exposure->minimum, max, in sc4336_set_ctrl()
1156 sc4336->exposure->step, in sc4336_set_ctrl()
1157 sc4336->exposure->default_value); in sc4336_set_ctrl()
1167 if (sc4336->cur_mode->hdr_mode == NO_HDR) { in sc4336_set_ctrl()
1170 ret = sc4336_write_reg(sc4336->client, in sc4336_set_ctrl()
1174 ret |= sc4336_write_reg(sc4336->client, in sc4336_set_ctrl()
1178 ret |= sc4336_write_reg(sc4336->client, in sc4336_set_ctrl()
1186 if (sc4336->cur_mode->hdr_mode == NO_HDR) in sc4336_set_ctrl()
1187 ret = sc4336_set_gain_reg(sc4336, ctrl->val); in sc4336_set_ctrl()
1191 ret = sc4336_write_reg(sc4336->client, in sc4336_set_ctrl()
1194 (ctrl->val + sc4336->cur_mode->height) in sc4336_set_ctrl()
1196 ret |= sc4336_write_reg(sc4336->client, in sc4336_set_ctrl()
1199 (ctrl->val + sc4336->cur_mode->height) in sc4336_set_ctrl()
1201 sc4336->cur_vts = ctrl->val + sc4336->cur_mode->height; in sc4336_set_ctrl()
1202 sc4336_modify_fps_info(sc4336); in sc4336_set_ctrl()
1205 ret = sc4336_enable_test_pattern(sc4336, ctrl->val); in sc4336_set_ctrl()
1208 ret = sc4336_read_reg(sc4336->client, SC4336_FLIP_MIRROR_REG, in sc4336_set_ctrl()
1210 ret |= sc4336_write_reg(sc4336->client, SC4336_FLIP_MIRROR_REG, in sc4336_set_ctrl()
1215 ret = sc4336_read_reg(sc4336->client, SC4336_FLIP_MIRROR_REG, in sc4336_set_ctrl()
1217 ret |= sc4336_write_reg(sc4336->client, SC4336_FLIP_MIRROR_REG, in sc4336_set_ctrl()
1236 static int sc4336_initialize_controls(struct sc4336 *sc4336) in sc4336_initialize_controls() argument
1245 handler = &sc4336->ctrl_handler; in sc4336_initialize_controls()
1246 mode = sc4336->cur_mode; in sc4336_initialize_controls()
1250 handler->lock = &sc4336->mutex; in sc4336_initialize_controls()
1261 sc4336->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in sc4336_initialize_controls()
1263 if (sc4336->hblank) in sc4336_initialize_controls()
1264 sc4336->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in sc4336_initialize_controls()
1266 sc4336->vblank = v4l2_ctrl_new_std(handler, &sc4336_ctrl_ops, in sc4336_initialize_controls()
1270 sc4336->cur_fps = mode->max_fps; in sc4336_initialize_controls()
1272 sc4336->exposure = v4l2_ctrl_new_std(handler, &sc4336_ctrl_ops, in sc4336_initialize_controls()
1276 sc4336->anal_gain = v4l2_ctrl_new_std(handler, &sc4336_ctrl_ops, in sc4336_initialize_controls()
1280 sc4336->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in sc4336_initialize_controls()
1291 dev_err(&sc4336->client->dev, in sc4336_initialize_controls()
1296 sc4336->subdev.ctrl_handler = handler; in sc4336_initialize_controls()
1306 static int sc4336_check_sensor_id(struct sc4336 *sc4336, in sc4336_check_sensor_id() argument
1309 struct device *dev = &sc4336->client->dev; in sc4336_check_sensor_id()
1313 if (sc4336->is_thunderboot) { in sc4336_check_sensor_id()
1330 static int sc4336_configure_regulators(struct sc4336 *sc4336) in sc4336_configure_regulators() argument
1335 sc4336->supplies[i].supply = sc4336_supply_names[i]; in sc4336_configure_regulators()
1337 return devm_regulator_bulk_get(&sc4336->client->dev, in sc4336_configure_regulators()
1339 sc4336->supplies); in sc4336_configure_regulators()
1347 struct sc4336 *sc4336; in sc4336_probe() local
1357 sc4336 = devm_kzalloc(dev, sizeof(*sc4336), GFP_KERNEL); in sc4336_probe()
1358 if (!sc4336) in sc4336_probe()
1362 &sc4336->module_index); in sc4336_probe()
1364 &sc4336->module_facing); in sc4336_probe()
1366 &sc4336->module_name); in sc4336_probe()
1368 &sc4336->len_name); in sc4336_probe()
1374 sc4336->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP); in sc4336_probe()
1375 sc4336->client = client; in sc4336_probe()
1376 sc4336->cur_mode = &supported_modes[0]; in sc4336_probe()
1378 sc4336->xvclk = devm_clk_get(dev, "xvclk"); in sc4336_probe()
1379 if (IS_ERR(sc4336->xvclk)) { in sc4336_probe()
1384 if (sc4336->is_thunderboot) { in sc4336_probe()
1385 sc4336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); in sc4336_probe()
1386 if (IS_ERR(sc4336->reset_gpio)) in sc4336_probe()
1389 sc4336->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS); in sc4336_probe()
1390 if (IS_ERR(sc4336->pwdn_gpio)) in sc4336_probe()
1393 sc4336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in sc4336_probe()
1394 if (IS_ERR(sc4336->reset_gpio)) in sc4336_probe()
1397 sc4336->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in sc4336_probe()
1398 if (IS_ERR(sc4336->pwdn_gpio)) in sc4336_probe()
1401 sc4336->pinctrl = devm_pinctrl_get(dev); in sc4336_probe()
1402 if (!IS_ERR(sc4336->pinctrl)) { in sc4336_probe()
1403 sc4336->pins_default = in sc4336_probe()
1404 pinctrl_lookup_state(sc4336->pinctrl, in sc4336_probe()
1406 if (IS_ERR(sc4336->pins_default)) in sc4336_probe()
1409 sc4336->pins_sleep = in sc4336_probe()
1410 pinctrl_lookup_state(sc4336->pinctrl, in sc4336_probe()
1412 if (IS_ERR(sc4336->pins_sleep)) in sc4336_probe()
1418 ret = sc4336_configure_regulators(sc4336); in sc4336_probe()
1424 mutex_init(&sc4336->mutex); in sc4336_probe()
1426 sd = &sc4336->subdev; in sc4336_probe()
1428 ret = sc4336_initialize_controls(sc4336); in sc4336_probe()
1432 ret = __sc4336_power_on(sc4336); in sc4336_probe()
1436 ret = sc4336_check_sensor_id(sc4336, client); in sc4336_probe()
1446 sc4336->pad.flags = MEDIA_PAD_FL_SOURCE; in sc4336_probe()
1448 ret = media_entity_pads_init(&sd->entity, 1, &sc4336->pad); in sc4336_probe()
1454 if (strcmp(sc4336->module_facing, "back") == 0) in sc4336_probe()
1460 sc4336->module_index, facing, in sc4336_probe()
1470 if (sc4336->is_thunderboot) in sc4336_probe()
1482 __sc4336_power_off(sc4336); in sc4336_probe()
1484 v4l2_ctrl_handler_free(&sc4336->ctrl_handler); in sc4336_probe()
1486 mutex_destroy(&sc4336->mutex); in sc4336_probe()
1494 struct sc4336 *sc4336 = to_sc4336(sd); in sc4336_remove() local
1500 v4l2_ctrl_handler_free(&sc4336->ctrl_handler); in sc4336_remove()
1501 mutex_destroy(&sc4336->mutex); in sc4336_remove()
1505 __sc4336_power_off(sc4336); in sc4336_remove()