Lines Matching refs:sc5336
125 struct sc5336 { struct
159 #define to_sc5336(sd) container_of(sd, struct sc5336, subdev) argument
458 static int sc5336_set_gain_reg(struct sc5336 *sc5336, u32 gain) in sc5336_set_gain_reg() argument
513 ret = sc5336_write_reg(sc5336->client, in sc5336_set_gain_reg()
517 ret |= sc5336_write_reg(sc5336->client, in sc5336_set_gain_reg()
521 ret |= sc5336_write_reg(sc5336->client, in sc5336_set_gain_reg()
560 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_set_fmt() local
564 mutex_lock(&sc5336->mutex); in sc5336_set_fmt()
575 mutex_unlock(&sc5336->mutex); in sc5336_set_fmt()
579 sc5336->cur_mode = mode; in sc5336_set_fmt()
581 __v4l2_ctrl_modify_range(sc5336->hblank, h_blank, in sc5336_set_fmt()
584 __v4l2_ctrl_modify_range(sc5336->vblank, vblank_def, in sc5336_set_fmt()
587 sc5336->cur_fps = mode->max_fps; in sc5336_set_fmt()
590 mutex_unlock(&sc5336->mutex); in sc5336_set_fmt()
599 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_get_fmt() local
600 const struct sc5336_mode *mode = sc5336->cur_mode; in sc5336_get_fmt()
602 mutex_lock(&sc5336->mutex); in sc5336_get_fmt()
607 mutex_unlock(&sc5336->mutex); in sc5336_get_fmt()
621 mutex_unlock(&sc5336->mutex); in sc5336_get_fmt()
630 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_enum_mbus_code() local
634 code->code = sc5336->cur_mode->bus_fmt; in sc5336_enum_mbus_code()
657 static int sc5336_enable_test_pattern(struct sc5336 *sc5336, u32 pattern) in sc5336_enable_test_pattern() argument
662 ret |= sc5336_write_reg(sc5336->client, 0x4501, SC5336_REG_VALUE_08BIT, 0xac); in sc5336_enable_test_pattern()
663 ret |= sc5336_write_reg(sc5336->client, 0x3902, SC5336_REG_VALUE_08BIT, 0x80); in sc5336_enable_test_pattern()
664 ret |= sc5336_write_reg(sc5336->client, 0x3e07, SC5336_REG_VALUE_08BIT, 0x40); in sc5336_enable_test_pattern()
666 ret |= sc5336_write_reg(sc5336->client, 0x4501, SC5336_REG_VALUE_08BIT, 0xa4); in sc5336_enable_test_pattern()
667 ret |= sc5336_write_reg(sc5336->client, 0x3902, SC5336_REG_VALUE_08BIT, 0xc0); in sc5336_enable_test_pattern()
668 ret |= sc5336_write_reg(sc5336->client, 0x3e07, SC5336_REG_VALUE_08BIT, 0x80); in sc5336_enable_test_pattern()
677 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_g_frame_interval() local
678 const struct sc5336_mode *mode = sc5336->cur_mode; in sc5336_g_frame_interval()
680 if (sc5336->streaming) in sc5336_g_frame_interval()
681 fi->interval = sc5336->cur_fps; in sc5336_g_frame_interval()
692 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_g_mbus_config() local
693 const struct sc5336_mode *mode = sc5336->cur_mode; in sc5336_g_mbus_config()
709 static void sc5336_get_module_inf(struct sc5336 *sc5336, in sc5336_get_module_inf() argument
714 strscpy(inf->base.module, sc5336->module_name, in sc5336_get_module_inf()
716 strscpy(inf->base.lens, sc5336->len_name, sizeof(inf->base.lens)); in sc5336_get_module_inf()
721 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_ioctl() local
729 sc5336_get_module_inf(sc5336, (struct rkmodule_inf *)arg); in sc5336_ioctl()
734 hdr->hdr_mode = sc5336->cur_mode->hdr_mode; in sc5336_ioctl()
738 w = sc5336->cur_mode->width; in sc5336_ioctl()
739 h = sc5336->cur_mode->height; in sc5336_ioctl()
744 sc5336->cur_mode = &supported_modes[i]; in sc5336_ioctl()
749 dev_err(&sc5336->client->dev, in sc5336_ioctl()
754 w = sc5336->cur_mode->hts_def - sc5336->cur_mode->width; in sc5336_ioctl()
755 h = sc5336->cur_mode->vts_def - sc5336->cur_mode->height; in sc5336_ioctl()
756 __v4l2_ctrl_modify_range(sc5336->hblank, w, w, 1, w); in sc5336_ioctl()
757 __v4l2_ctrl_modify_range(sc5336->vblank, h, in sc5336_ioctl()
758 SC5336_VTS_MAX - sc5336->cur_mode->height, 1, h); in sc5336_ioctl()
768 ret = sc5336_write_reg(sc5336->client, SC5336_REG_CTRL_MODE, in sc5336_ioctl()
771 ret = sc5336_write_reg(sc5336->client, SC5336_REG_CTRL_MODE, in sc5336_ioctl()
866 static int __sc5336_start_stream(struct sc5336 *sc5336) in __sc5336_start_stream() argument
870 if (!sc5336->is_thunderboot) { in __sc5336_start_stream()
871 ret = sc5336_write_array(sc5336->client, sc5336->cur_mode->reg_list); in __sc5336_start_stream()
876 ret = __v4l2_ctrl_handler_setup(&sc5336->ctrl_handler); in __sc5336_start_stream()
881 return sc5336_write_reg(sc5336->client, SC5336_REG_CTRL_MODE, in __sc5336_start_stream()
885 static int __sc5336_stop_stream(struct sc5336 *sc5336) in __sc5336_stop_stream() argument
887 if (sc5336->is_thunderboot) { in __sc5336_stop_stream()
888 sc5336->is_first_streamoff = true; in __sc5336_stop_stream()
889 pm_runtime_put(&sc5336->client->dev); in __sc5336_stop_stream()
891 return sc5336_write_reg(sc5336->client, SC5336_REG_CTRL_MODE, in __sc5336_stop_stream()
895 static int __sc5336_power_on(struct sc5336 *sc5336);
898 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_s_stream() local
899 struct i2c_client *client = sc5336->client; in sc5336_s_stream()
902 mutex_lock(&sc5336->mutex); in sc5336_s_stream()
904 if (on == sc5336->streaming) in sc5336_s_stream()
908 if (sc5336->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) { in sc5336_s_stream()
909 sc5336->is_thunderboot = false; in sc5336_s_stream()
910 __sc5336_power_on(sc5336); in sc5336_s_stream()
919 ret = __sc5336_start_stream(sc5336); in sc5336_s_stream()
926 __sc5336_stop_stream(sc5336); in sc5336_s_stream()
930 sc5336->streaming = on; in sc5336_s_stream()
933 mutex_unlock(&sc5336->mutex); in sc5336_s_stream()
940 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_s_power() local
941 struct i2c_client *client = sc5336->client; in sc5336_s_power()
944 mutex_lock(&sc5336->mutex); in sc5336_s_power()
947 if (sc5336->power_on == !!on) in sc5336_s_power()
957 if (!sc5336->is_thunderboot) { in sc5336_s_power()
958 ret = sc5336_write_array(sc5336->client, sc5336_global_regs); in sc5336_s_power()
966 sc5336->power_on = true; in sc5336_s_power()
969 sc5336->power_on = false; in sc5336_s_power()
973 mutex_unlock(&sc5336->mutex); in sc5336_s_power()
984 static int __sc5336_power_on(struct sc5336 *sc5336) in __sc5336_power_on() argument
988 struct device *dev = &sc5336->client->dev; in __sc5336_power_on()
990 if (!IS_ERR_OR_NULL(sc5336->pins_default)) { in __sc5336_power_on()
991 ret = pinctrl_select_state(sc5336->pinctrl, in __sc5336_power_on()
992 sc5336->pins_default); in __sc5336_power_on()
996 ret = clk_set_rate(sc5336->xvclk, SC5336_XVCLK_FREQ); in __sc5336_power_on()
999 if (clk_get_rate(sc5336->xvclk) != SC5336_XVCLK_FREQ) in __sc5336_power_on()
1001 ret = clk_prepare_enable(sc5336->xvclk); in __sc5336_power_on()
1006 if (sc5336->is_thunderboot) in __sc5336_power_on()
1009 if (!IS_ERR(sc5336->reset_gpio)) in __sc5336_power_on()
1010 gpiod_set_value_cansleep(sc5336->reset_gpio, 0); in __sc5336_power_on()
1012 ret = regulator_bulk_enable(SC5336_NUM_SUPPLIES, sc5336->supplies); in __sc5336_power_on()
1018 if (!IS_ERR(sc5336->reset_gpio)) in __sc5336_power_on()
1019 gpiod_set_value_cansleep(sc5336->reset_gpio, 1); in __sc5336_power_on()
1022 if (!IS_ERR(sc5336->pwdn_gpio)) in __sc5336_power_on()
1023 gpiod_set_value_cansleep(sc5336->pwdn_gpio, 1); in __sc5336_power_on()
1025 if (!IS_ERR(sc5336->reset_gpio)) in __sc5336_power_on()
1037 clk_disable_unprepare(sc5336->xvclk); in __sc5336_power_on()
1042 static void __sc5336_power_off(struct sc5336 *sc5336) in __sc5336_power_off() argument
1045 struct device *dev = &sc5336->client->dev; in __sc5336_power_off()
1047 clk_disable_unprepare(sc5336->xvclk); in __sc5336_power_off()
1048 if (sc5336->is_thunderboot) { in __sc5336_power_off()
1049 if (sc5336->is_first_streamoff) { in __sc5336_power_off()
1050 sc5336->is_thunderboot = false; in __sc5336_power_off()
1051 sc5336->is_first_streamoff = false; in __sc5336_power_off()
1057 if (!IS_ERR(sc5336->pwdn_gpio)) in __sc5336_power_off()
1058 gpiod_set_value_cansleep(sc5336->pwdn_gpio, 0); in __sc5336_power_off()
1059 if (!IS_ERR(sc5336->reset_gpio)) in __sc5336_power_off()
1060 gpiod_set_value_cansleep(sc5336->reset_gpio, 0); in __sc5336_power_off()
1061 if (!IS_ERR_OR_NULL(sc5336->pins_sleep)) { in __sc5336_power_off()
1062 ret = pinctrl_select_state(sc5336->pinctrl, in __sc5336_power_off()
1063 sc5336->pins_sleep); in __sc5336_power_off()
1067 regulator_bulk_disable(SC5336_NUM_SUPPLIES, sc5336->supplies); in __sc5336_power_off()
1074 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_runtime_resume() local
1076 return __sc5336_power_on(sc5336); in sc5336_runtime_resume()
1083 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_runtime_suspend() local
1085 __sc5336_power_off(sc5336); in sc5336_runtime_suspend()
1093 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_open() local
1098 mutex_lock(&sc5336->mutex); in sc5336_open()
1105 mutex_unlock(&sc5336->mutex); in sc5336_open()
1166 static void sc5336_modify_fps_info(struct sc5336 *sc5336) in sc5336_modify_fps_info() argument
1168 const struct sc5336_mode *mode = sc5336->cur_mode; in sc5336_modify_fps_info()
1170 sc5336->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def / in sc5336_modify_fps_info()
1171 sc5336->cur_vts; in sc5336_modify_fps_info()
1176 struct sc5336 *sc5336 = container_of(ctrl->handler, in sc5336_set_ctrl() local
1177 struct sc5336, ctrl_handler); in sc5336_set_ctrl()
1178 struct i2c_client *client = sc5336->client; in sc5336_set_ctrl()
1187 max = sc5336->cur_mode->height + ctrl->val - 8; in sc5336_set_ctrl()
1188 __v4l2_ctrl_modify_range(sc5336->exposure, in sc5336_set_ctrl()
1189 sc5336->exposure->minimum, max, in sc5336_set_ctrl()
1190 sc5336->exposure->step, in sc5336_set_ctrl()
1191 sc5336->exposure->default_value); in sc5336_set_ctrl()
1201 if (sc5336->cur_mode->hdr_mode == NO_HDR) { in sc5336_set_ctrl()
1204 ret = sc5336_write_reg(sc5336->client, in sc5336_set_ctrl()
1208 ret |= sc5336_write_reg(sc5336->client, in sc5336_set_ctrl()
1212 ret |= sc5336_write_reg(sc5336->client, in sc5336_set_ctrl()
1220 if (sc5336->cur_mode->hdr_mode == NO_HDR) in sc5336_set_ctrl()
1221 ret = sc5336_set_gain_reg(sc5336, ctrl->val); in sc5336_set_ctrl()
1225 ret = sc5336_write_reg(sc5336->client, in sc5336_set_ctrl()
1228 (ctrl->val + sc5336->cur_mode->height) in sc5336_set_ctrl()
1230 ret |= sc5336_write_reg(sc5336->client, in sc5336_set_ctrl()
1233 (ctrl->val + sc5336->cur_mode->height) in sc5336_set_ctrl()
1235 sc5336->cur_vts = ctrl->val + sc5336->cur_mode->height; in sc5336_set_ctrl()
1236 if (sc5336->cur_vts != sc5336->cur_mode->vts_def) in sc5336_set_ctrl()
1237 sc5336_modify_fps_info(sc5336); in sc5336_set_ctrl()
1240 ret = sc5336_enable_test_pattern(sc5336, ctrl->val); in sc5336_set_ctrl()
1243 ret = sc5336_read_reg(sc5336->client, SC5336_FLIP_MIRROR_REG, in sc5336_set_ctrl()
1245 ret |= sc5336_write_reg(sc5336->client, SC5336_FLIP_MIRROR_REG, in sc5336_set_ctrl()
1250 ret = sc5336_read_reg(sc5336->client, SC5336_FLIP_MIRROR_REG, in sc5336_set_ctrl()
1252 ret |= sc5336_write_reg(sc5336->client, SC5336_FLIP_MIRROR_REG, in sc5336_set_ctrl()
1271 static int sc5336_initialize_controls(struct sc5336 *sc5336) in sc5336_initialize_controls() argument
1280 handler = &sc5336->ctrl_handler; in sc5336_initialize_controls()
1281 mode = sc5336->cur_mode; in sc5336_initialize_controls()
1285 handler->lock = &sc5336->mutex; in sc5336_initialize_controls()
1296 sc5336->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in sc5336_initialize_controls()
1298 if (sc5336->hblank) in sc5336_initialize_controls()
1299 sc5336->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in sc5336_initialize_controls()
1301 sc5336->vblank = v4l2_ctrl_new_std(handler, &sc5336_ctrl_ops, in sc5336_initialize_controls()
1305 sc5336->cur_fps = mode->max_fps; in sc5336_initialize_controls()
1307 sc5336->exposure = v4l2_ctrl_new_std(handler, &sc5336_ctrl_ops, in sc5336_initialize_controls()
1311 sc5336->anal_gain = v4l2_ctrl_new_std(handler, &sc5336_ctrl_ops, in sc5336_initialize_controls()
1315 sc5336->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in sc5336_initialize_controls()
1326 dev_err(&sc5336->client->dev, in sc5336_initialize_controls()
1331 sc5336->subdev.ctrl_handler = handler; in sc5336_initialize_controls()
1341 static int sc5336_check_sensor_id(struct sc5336 *sc5336, in sc5336_check_sensor_id() argument
1344 struct device *dev = &sc5336->client->dev; in sc5336_check_sensor_id()
1348 if (sc5336->is_thunderboot) { in sc5336_check_sensor_id()
1365 static int sc5336_configure_regulators(struct sc5336 *sc5336) in sc5336_configure_regulators() argument
1370 sc5336->supplies[i].supply = sc5336_supply_names[i]; in sc5336_configure_regulators()
1372 return devm_regulator_bulk_get(&sc5336->client->dev, in sc5336_configure_regulators()
1374 sc5336->supplies); in sc5336_configure_regulators()
1382 struct sc5336 *sc5336; in sc5336_probe() local
1392 sc5336 = devm_kzalloc(dev, sizeof(*sc5336), GFP_KERNEL); in sc5336_probe()
1393 if (!sc5336) in sc5336_probe()
1397 &sc5336->module_index); in sc5336_probe()
1399 &sc5336->module_facing); in sc5336_probe()
1401 &sc5336->module_name); in sc5336_probe()
1403 &sc5336->len_name); in sc5336_probe()
1409 sc5336->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP); in sc5336_probe()
1410 sc5336->client = client; in sc5336_probe()
1411 sc5336->cur_mode = &supported_modes[0]; in sc5336_probe()
1413 sc5336->xvclk = devm_clk_get(dev, "xvclk"); in sc5336_probe()
1414 if (IS_ERR(sc5336->xvclk)) { in sc5336_probe()
1419 if (sc5336->is_thunderboot) { in sc5336_probe()
1420 sc5336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); in sc5336_probe()
1421 if (IS_ERR(sc5336->reset_gpio)) in sc5336_probe()
1424 sc5336->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS); in sc5336_probe()
1425 if (IS_ERR(sc5336->pwdn_gpio)) in sc5336_probe()
1428 sc5336->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in sc5336_probe()
1429 if (IS_ERR(sc5336->reset_gpio)) in sc5336_probe()
1432 sc5336->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in sc5336_probe()
1433 if (IS_ERR(sc5336->pwdn_gpio)) in sc5336_probe()
1436 sc5336->pinctrl = devm_pinctrl_get(dev); in sc5336_probe()
1437 if (!IS_ERR(sc5336->pinctrl)) { in sc5336_probe()
1438 sc5336->pins_default = in sc5336_probe()
1439 pinctrl_lookup_state(sc5336->pinctrl, in sc5336_probe()
1441 if (IS_ERR(sc5336->pins_default)) in sc5336_probe()
1444 sc5336->pins_sleep = in sc5336_probe()
1445 pinctrl_lookup_state(sc5336->pinctrl, in sc5336_probe()
1447 if (IS_ERR(sc5336->pins_sleep)) in sc5336_probe()
1453 ret = sc5336_configure_regulators(sc5336); in sc5336_probe()
1459 mutex_init(&sc5336->mutex); in sc5336_probe()
1461 sd = &sc5336->subdev; in sc5336_probe()
1463 ret = sc5336_initialize_controls(sc5336); in sc5336_probe()
1467 ret = __sc5336_power_on(sc5336); in sc5336_probe()
1471 ret = sc5336_check_sensor_id(sc5336, client); in sc5336_probe()
1481 sc5336->pad.flags = MEDIA_PAD_FL_SOURCE; in sc5336_probe()
1483 ret = media_entity_pads_init(&sd->entity, 1, &sc5336->pad); in sc5336_probe()
1489 if (strcmp(sc5336->module_facing, "back") == 0) in sc5336_probe()
1495 sc5336->module_index, facing, in sc5336_probe()
1505 if (sc5336->is_thunderboot) in sc5336_probe()
1517 __sc5336_power_off(sc5336); in sc5336_probe()
1519 v4l2_ctrl_handler_free(&sc5336->ctrl_handler); in sc5336_probe()
1521 mutex_destroy(&sc5336->mutex); in sc5336_probe()
1529 struct sc5336 *sc5336 = to_sc5336(sd); in sc5336_remove() local
1535 v4l2_ctrl_handler_free(&sc5336->ctrl_handler); in sc5336_remove()
1536 mutex_destroy(&sc5336->mutex); in sc5336_remove()
1540 __sc5336_power_off(sc5336); in sc5336_remove()