Lines Matching refs:sc2336
128 struct sc2336 { struct
164 #define to_sc2336(sd) container_of(sd, struct sc2336, subdev) argument
439 static int sc2336_set_gain_reg(struct sc2336 *sc2336, u32 gain) in sc2336_set_gain_reg() argument
484 dev_dbg(&sc2336->client->dev, in sc2336_set_gain_reg()
488 ret = sc2336_write_reg(sc2336->client, in sc2336_set_gain_reg()
492 ret |= sc2336_write_reg(sc2336->client, in sc2336_set_gain_reg()
496 ret |= sc2336_write_reg(sc2336->client, in sc2336_set_gain_reg()
535 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_set_fmt() local
541 mutex_lock(&sc2336->mutex); in sc2336_set_fmt()
552 mutex_unlock(&sc2336->mutex); in sc2336_set_fmt()
556 sc2336->cur_mode = mode; in sc2336_set_fmt()
558 __v4l2_ctrl_modify_range(sc2336->hblank, h_blank, in sc2336_set_fmt()
561 __v4l2_ctrl_modify_range(sc2336->vblank, vblank_def, in sc2336_set_fmt()
567 __v4l2_ctrl_s_ctrl_int64(sc2336->pixel_rate, in sc2336_set_fmt()
569 __v4l2_ctrl_s_ctrl(sc2336->link_freq, in sc2336_set_fmt()
573 mutex_unlock(&sc2336->mutex); in sc2336_set_fmt()
582 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_get_fmt() local
583 const struct sc2336_mode *mode = sc2336->cur_mode; in sc2336_get_fmt()
585 mutex_lock(&sc2336->mutex); in sc2336_get_fmt()
590 mutex_unlock(&sc2336->mutex); in sc2336_get_fmt()
604 mutex_unlock(&sc2336->mutex); in sc2336_get_fmt()
613 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_enum_mbus_code() local
617 code->code = sc2336->cur_mode->bus_fmt; in sc2336_enum_mbus_code()
640 static int sc2336_enable_test_pattern(struct sc2336 *sc2336, u32 pattern) in sc2336_enable_test_pattern() argument
645 ret = sc2336_read_reg(sc2336->client, SC2336_REG_TEST_PATTERN, in sc2336_enable_test_pattern()
652 ret |= sc2336_write_reg(sc2336->client, SC2336_REG_TEST_PATTERN, in sc2336_enable_test_pattern()
660 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_g_frame_interval() local
661 const struct sc2336_mode *mode = sc2336->cur_mode; in sc2336_g_frame_interval()
672 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_g_mbus_config() local
673 const struct sc2336_mode *mode = sc2336->cur_mode; in sc2336_g_mbus_config()
690 static void sc2336_get_module_inf(struct sc2336 *sc2336, in sc2336_get_module_inf() argument
695 strscpy(inf->base.module, sc2336->module_name, in sc2336_get_module_inf()
697 strscpy(inf->base.lens, sc2336->len_name, sizeof(inf->base.lens)); in sc2336_get_module_inf()
702 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_ioctl() local
710 sc2336_get_module_inf(sc2336, (struct rkmodule_inf *)arg); in sc2336_ioctl()
715 hdr->hdr_mode = sc2336->cur_mode->hdr_mode; in sc2336_ioctl()
719 w = sc2336->cur_mode->width; in sc2336_ioctl()
720 h = sc2336->cur_mode->height; in sc2336_ioctl()
725 sc2336->cur_mode = &supported_modes[i]; in sc2336_ioctl()
730 dev_err(&sc2336->client->dev, in sc2336_ioctl()
735 w = sc2336->cur_mode->hts_def - sc2336->cur_mode->width; in sc2336_ioctl()
736 h = sc2336->cur_mode->vts_def - sc2336->cur_mode->height; in sc2336_ioctl()
737 __v4l2_ctrl_modify_range(sc2336->hblank, w, w, 1, w); in sc2336_ioctl()
738 __v4l2_ctrl_modify_range(sc2336->vblank, h, in sc2336_ioctl()
739 SC2336_VTS_MAX - sc2336->cur_mode->height, 1, h); in sc2336_ioctl()
749 ret = sc2336_write_reg(sc2336->client, SC2336_REG_CTRL_MODE, in sc2336_ioctl()
752 ret = sc2336_write_reg(sc2336->client, SC2336_REG_CTRL_MODE, in sc2336_ioctl()
847 static int __sc2336_start_stream(struct sc2336 *sc2336) in __sc2336_start_stream() argument
851 if (!sc2336->is_thunderboot) { in __sc2336_start_stream()
852 ret = sc2336_write_array(sc2336->client, sc2336->cur_mode->reg_list); in __sc2336_start_stream()
856 ret = __v4l2_ctrl_handler_setup(&sc2336->ctrl_handler); in __sc2336_start_stream()
859 if (sc2336->has_init_exp && sc2336->cur_mode->hdr_mode != NO_HDR) { in __sc2336_start_stream()
860 ret = sc2336_ioctl(&sc2336->subdev, PREISP_CMD_SET_HDRAE_EXP, in __sc2336_start_stream()
861 &sc2336->init_hdrae_exp); in __sc2336_start_stream()
863 dev_err(&sc2336->client->dev, in __sc2336_start_stream()
869 ret = sc2336_write_reg(sc2336->client, SC2336_REG_CTRL_MODE, in __sc2336_start_stream()
874 static int __sc2336_stop_stream(struct sc2336 *sc2336) in __sc2336_stop_stream() argument
876 sc2336->has_init_exp = false; in __sc2336_stop_stream()
877 if (sc2336->is_thunderboot) { in __sc2336_stop_stream()
878 sc2336->is_first_streamoff = true; in __sc2336_stop_stream()
879 pm_runtime_put(&sc2336->client->dev); in __sc2336_stop_stream()
881 return sc2336_write_reg(sc2336->client, SC2336_REG_CTRL_MODE, in __sc2336_stop_stream()
885 static int __sc2336_power_on(struct sc2336 *sc2336);
888 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_s_stream() local
889 struct i2c_client *client = sc2336->client; in sc2336_s_stream()
892 mutex_lock(&sc2336->mutex); in sc2336_s_stream()
894 if (on == sc2336->streaming) in sc2336_s_stream()
897 if (sc2336->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) { in sc2336_s_stream()
898 sc2336->is_thunderboot = false; in sc2336_s_stream()
899 __sc2336_power_on(sc2336); in sc2336_s_stream()
906 ret = __sc2336_start_stream(sc2336); in sc2336_s_stream()
913 __sc2336_stop_stream(sc2336); in sc2336_s_stream()
917 sc2336->streaming = on; in sc2336_s_stream()
919 mutex_unlock(&sc2336->mutex); in sc2336_s_stream()
925 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_s_power() local
926 struct i2c_client *client = sc2336->client; in sc2336_s_power()
929 mutex_lock(&sc2336->mutex); in sc2336_s_power()
932 if (sc2336->power_on == !!on) in sc2336_s_power()
942 if (!sc2336->is_thunderboot) { in sc2336_s_power()
943 ret = sc2336_write_array(sc2336->client, sc2336_global_regs); in sc2336_s_power()
951 sc2336->power_on = true; in sc2336_s_power()
954 sc2336->power_on = false; in sc2336_s_power()
958 mutex_unlock(&sc2336->mutex); in sc2336_s_power()
964 static inline u32 sc2336_cal_delay(u32 cycles, struct sc2336 *sc2336) in sc2336_cal_delay() argument
966 return DIV_ROUND_UP(cycles, sc2336->cur_mode->xvclk_freq / 1000 / 1000); in sc2336_cal_delay()
969 static int __sc2336_power_on(struct sc2336 *sc2336) in __sc2336_power_on() argument
973 struct device *dev = &sc2336->client->dev; in __sc2336_power_on()
975 if (!IS_ERR_OR_NULL(sc2336->pins_default)) { in __sc2336_power_on()
976 ret = pinctrl_select_state(sc2336->pinctrl, in __sc2336_power_on()
977 sc2336->pins_default); in __sc2336_power_on()
981 ret = clk_set_rate(sc2336->xvclk, sc2336->cur_mode->xvclk_freq); in __sc2336_power_on()
983 dev_warn(dev, "Failed to set xvclk rate (%dHz)\n", sc2336->cur_mode->xvclk_freq); in __sc2336_power_on()
984 if (clk_get_rate(sc2336->xvclk) != sc2336->cur_mode->xvclk_freq) in __sc2336_power_on()
986 sc2336->cur_mode->xvclk_freq); in __sc2336_power_on()
987 ret = clk_prepare_enable(sc2336->xvclk); in __sc2336_power_on()
993 if (sc2336->is_thunderboot) in __sc2336_power_on()
996 if (!IS_ERR(sc2336->reset_gpio)) in __sc2336_power_on()
997 gpiod_set_value_cansleep(sc2336->reset_gpio, 0); in __sc2336_power_on()
999 ret = regulator_bulk_enable(SC2336_NUM_SUPPLIES, sc2336->supplies); in __sc2336_power_on()
1005 if (!IS_ERR(sc2336->reset_gpio)) in __sc2336_power_on()
1006 gpiod_set_value_cansleep(sc2336->reset_gpio, 1); in __sc2336_power_on()
1010 if (!IS_ERR(sc2336->reset_gpio)) in __sc2336_power_on()
1016 delay_us = sc2336_cal_delay(8192, sc2336); in __sc2336_power_on()
1022 clk_disable_unprepare(sc2336->xvclk); in __sc2336_power_on()
1027 static void __sc2336_power_off(struct sc2336 *sc2336) in __sc2336_power_off() argument
1030 struct device *dev = &sc2336->client->dev; in __sc2336_power_off()
1032 clk_disable_unprepare(sc2336->xvclk); in __sc2336_power_off()
1033 if (sc2336->is_thunderboot) { in __sc2336_power_off()
1034 if (sc2336->is_first_streamoff) { in __sc2336_power_off()
1035 sc2336->is_thunderboot = false; in __sc2336_power_off()
1036 sc2336->is_first_streamoff = false; in __sc2336_power_off()
1042 if (!IS_ERR(sc2336->reset_gpio)) in __sc2336_power_off()
1043 gpiod_set_value_cansleep(sc2336->reset_gpio, 0); in __sc2336_power_off()
1044 if (!IS_ERR_OR_NULL(sc2336->pins_sleep)) { in __sc2336_power_off()
1045 ret = pinctrl_select_state(sc2336->pinctrl, in __sc2336_power_off()
1046 sc2336->pins_sleep); in __sc2336_power_off()
1050 regulator_bulk_disable(SC2336_NUM_SUPPLIES, sc2336->supplies); in __sc2336_power_off()
1057 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_runtime_resume() local
1059 return __sc2336_power_on(sc2336); in sc2336_runtime_resume()
1066 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_runtime_suspend() local
1068 __sc2336_power_off(sc2336); in sc2336_runtime_suspend()
1076 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_open() local
1081 mutex_lock(&sc2336->mutex); in sc2336_open()
1088 mutex_unlock(&sc2336->mutex); in sc2336_open()
1151 struct sc2336 *sc2336 = container_of(ctrl->handler, in sc2336_set_ctrl() local
1152 struct sc2336, ctrl_handler); in sc2336_set_ctrl()
1153 struct i2c_client *client = sc2336->client; in sc2336_set_ctrl()
1162 max = sc2336->cur_mode->height + ctrl->val - 8; in sc2336_set_ctrl()
1163 __v4l2_ctrl_modify_range(sc2336->exposure, in sc2336_set_ctrl()
1164 sc2336->exposure->minimum, max, in sc2336_set_ctrl()
1165 sc2336->exposure->step, in sc2336_set_ctrl()
1166 sc2336->exposure->default_value); in sc2336_set_ctrl()
1176 if (sc2336->cur_mode->hdr_mode == NO_HDR) { in sc2336_set_ctrl()
1179 ret = sc2336_write_reg(sc2336->client, in sc2336_set_ctrl()
1183 ret |= sc2336_write_reg(sc2336->client, in sc2336_set_ctrl()
1187 ret |= sc2336_write_reg(sc2336->client, in sc2336_set_ctrl()
1195 if (sc2336->cur_mode->hdr_mode == NO_HDR) in sc2336_set_ctrl()
1196 ret = sc2336_set_gain_reg(sc2336, ctrl->val); in sc2336_set_ctrl()
1200 ret = sc2336_write_reg(sc2336->client, in sc2336_set_ctrl()
1203 (ctrl->val + sc2336->cur_mode->height) in sc2336_set_ctrl()
1205 ret |= sc2336_write_reg(sc2336->client, in sc2336_set_ctrl()
1208 (ctrl->val + sc2336->cur_mode->height) in sc2336_set_ctrl()
1210 sc2336->cur_vts = ctrl->val + sc2336->cur_mode->height; in sc2336_set_ctrl()
1213 ret = sc2336_enable_test_pattern(sc2336, ctrl->val); in sc2336_set_ctrl()
1216 ret = sc2336_read_reg(sc2336->client, SC2336_FLIP_MIRROR_REG, in sc2336_set_ctrl()
1218 ret |= sc2336_write_reg(sc2336->client, SC2336_FLIP_MIRROR_REG, in sc2336_set_ctrl()
1223 ret = sc2336_read_reg(sc2336->client, SC2336_FLIP_MIRROR_REG, in sc2336_set_ctrl()
1225 ret |= sc2336_write_reg(sc2336->client, SC2336_FLIP_MIRROR_REG, in sc2336_set_ctrl()
1244 static int sc2336_initialize_controls(struct sc2336 *sc2336) in sc2336_initialize_controls() argument
1254 handler = &sc2336->ctrl_handler; in sc2336_initialize_controls()
1255 mode = sc2336->cur_mode; in sc2336_initialize_controls()
1259 handler->lock = &sc2336->mutex; in sc2336_initialize_controls()
1261 sc2336->link_freq = v4l2_ctrl_new_int_menu(handler, NULL, in sc2336_initialize_controls()
1264 if (sc2336->link_freq) in sc2336_initialize_controls()
1265 sc2336->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in sc2336_initialize_controls()
1270 sc2336->pixel_rate = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, in sc2336_initialize_controls()
1273 __v4l2_ctrl_s_ctrl(sc2336->link_freq, dst_link_freq); in sc2336_initialize_controls()
1276 sc2336->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in sc2336_initialize_controls()
1278 if (sc2336->hblank) in sc2336_initialize_controls()
1279 sc2336->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in sc2336_initialize_controls()
1281 sc2336->vblank = v4l2_ctrl_new_std(handler, &sc2336_ctrl_ops, in sc2336_initialize_controls()
1286 sc2336->exposure = v4l2_ctrl_new_std(handler, &sc2336_ctrl_ops, in sc2336_initialize_controls()
1290 sc2336->anal_gain = v4l2_ctrl_new_std(handler, &sc2336_ctrl_ops, in sc2336_initialize_controls()
1294 sc2336->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in sc2336_initialize_controls()
1305 dev_err(&sc2336->client->dev, in sc2336_initialize_controls()
1310 sc2336->subdev.ctrl_handler = handler; in sc2336_initialize_controls()
1311 sc2336->has_init_exp = false; in sc2336_initialize_controls()
1321 static int sc2336_check_sensor_id(struct sc2336 *sc2336, in sc2336_check_sensor_id() argument
1324 struct device *dev = &sc2336->client->dev; in sc2336_check_sensor_id()
1328 if (sc2336->is_thunderboot) { in sc2336_check_sensor_id()
1345 static int sc2336_configure_regulators(struct sc2336 *sc2336) in sc2336_configure_regulators() argument
1350 sc2336->supplies[i].supply = sc2336_supply_names[i]; in sc2336_configure_regulators()
1352 return devm_regulator_bulk_get(&sc2336->client->dev, in sc2336_configure_regulators()
1354 sc2336->supplies); in sc2336_configure_regulators()
1362 struct sc2336 *sc2336; in sc2336_probe() local
1373 sc2336 = devm_kzalloc(dev, sizeof(*sc2336), GFP_KERNEL); in sc2336_probe()
1374 if (!sc2336) in sc2336_probe()
1378 &sc2336->module_index); in sc2336_probe()
1380 &sc2336->module_facing); in sc2336_probe()
1382 &sc2336->module_name); in sc2336_probe()
1384 &sc2336->len_name); in sc2336_probe()
1390 sc2336->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP); in sc2336_probe()
1392 sc2336->client = client; in sc2336_probe()
1395 sc2336->cur_mode = &supported_modes[i]; in sc2336_probe()
1400 sc2336->cur_mode = &supported_modes[0]; in sc2336_probe()
1402 sc2336->xvclk = devm_clk_get(dev, "xvclk"); in sc2336_probe()
1403 if (IS_ERR(sc2336->xvclk)) { in sc2336_probe()
1408 if (sc2336->is_thunderboot) { in sc2336_probe()
1409 sc2336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); in sc2336_probe()
1410 if (IS_ERR(sc2336->reset_gpio)) in sc2336_probe()
1413 sc2336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in sc2336_probe()
1414 if (IS_ERR(sc2336->reset_gpio)) in sc2336_probe()
1418 sc2336->pinctrl = devm_pinctrl_get(dev); in sc2336_probe()
1419 if (!IS_ERR(sc2336->pinctrl)) { in sc2336_probe()
1420 sc2336->pins_default = in sc2336_probe()
1421 pinctrl_lookup_state(sc2336->pinctrl, in sc2336_probe()
1423 if (IS_ERR(sc2336->pins_default)) in sc2336_probe()
1426 sc2336->pins_sleep = in sc2336_probe()
1427 pinctrl_lookup_state(sc2336->pinctrl, in sc2336_probe()
1429 if (IS_ERR(sc2336->pins_sleep)) in sc2336_probe()
1435 ret = sc2336_configure_regulators(sc2336); in sc2336_probe()
1441 mutex_init(&sc2336->mutex); in sc2336_probe()
1443 sd = &sc2336->subdev; in sc2336_probe()
1445 ret = sc2336_initialize_controls(sc2336); in sc2336_probe()
1449 ret = __sc2336_power_on(sc2336); in sc2336_probe()
1453 ret = sc2336_check_sensor_id(sc2336, client); in sc2336_probe()
1463 sc2336->pad.flags = MEDIA_PAD_FL_SOURCE; in sc2336_probe()
1465 ret = media_entity_pads_init(&sd->entity, 1, &sc2336->pad); in sc2336_probe()
1471 if (strcmp(sc2336->module_facing, "back") == 0) in sc2336_probe()
1477 sc2336->module_index, facing, in sc2336_probe()
1487 if (sc2336->is_thunderboot) in sc2336_probe()
1499 __sc2336_power_off(sc2336); in sc2336_probe()
1501 v4l2_ctrl_handler_free(&sc2336->ctrl_handler); in sc2336_probe()
1503 mutex_destroy(&sc2336->mutex); in sc2336_probe()
1511 struct sc2336 *sc2336 = to_sc2336(sd); in sc2336_remove() local
1517 v4l2_ctrl_handler_free(&sc2336->ctrl_handler); in sc2336_remove()
1518 mutex_destroy(&sc2336->mutex); in sc2336_remove()
1522 __sc2336_power_off(sc2336); in sc2336_remove()