Lines Matching refs:sc2232
116 struct sc2232 { struct
150 #define to_sc2232(sd) container_of(sd, struct sc2232, subdev) argument
450 sc2232_find_best_fit(struct sc2232 *sc2232, struct v4l2_subdev_format *fmt) in sc2232_find_best_fit() argument
458 for (i = 0; i < sc2232->cfg_num; i++) { in sc2232_find_best_fit()
470 static void sc2232_change_mode(struct sc2232 *sc2232, const struct sc2232_mode *mode) in sc2232_change_mode() argument
472 sc2232->cur_mode = mode; in sc2232_change_mode()
473 sc2232->cur_vts = sc2232->cur_mode->vts_def; in sc2232_change_mode()
474 dev_info(&sc2232->client->dev, "set fmt: cur_mode: %dx%d, hdr: %d\n", in sc2232_change_mode()
482 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_set_fmt() local
487 mutex_lock(&sc2232->mutex); in sc2232_set_fmt()
489 mode = sc2232_find_best_fit(sc2232, fmt); in sc2232_set_fmt()
498 mutex_unlock(&sc2232->mutex); in sc2232_set_fmt()
502 sc2232_change_mode(sc2232, mode); in sc2232_set_fmt()
504 __v4l2_ctrl_modify_range(sc2232->hblank, h_blank, in sc2232_set_fmt()
507 __v4l2_ctrl_modify_range(sc2232->vblank, vblank_def, in sc2232_set_fmt()
510 __v4l2_ctrl_s_ctrl(sc2232->link_freq, mode->mipi_freq_idx); in sc2232_set_fmt()
513 __v4l2_ctrl_s_ctrl_int64(sc2232->pixel_rate, pixel_rate); in sc2232_set_fmt()
514 sc2232->cur_fps = mode->max_fps; in sc2232_set_fmt()
515 sc2232->cur_vts = mode->vts_def; in sc2232_set_fmt()
518 mutex_unlock(&sc2232->mutex); in sc2232_set_fmt()
527 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_get_fmt() local
528 const struct sc2232_mode *mode = sc2232->cur_mode; in sc2232_get_fmt()
530 mutex_lock(&sc2232->mutex); in sc2232_get_fmt()
535 mutex_unlock(&sc2232->mutex); in sc2232_get_fmt()
548 mutex_unlock(&sc2232->mutex); in sc2232_get_fmt()
557 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_enum_mbus_code() local
561 code->code = sc2232->cur_mode->bus_fmt; in sc2232_enum_mbus_code()
570 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_enum_frame_sizes() local
572 if (fse->index >= sc2232->cfg_num) in sc2232_enum_frame_sizes()
589 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_g_frame_interval() local
590 const struct sc2232_mode *mode = sc2232->cur_mode; in sc2232_g_frame_interval()
592 if (sc2232->streaming) in sc2232_g_frame_interval()
593 fi->interval = sc2232->cur_fps; in sc2232_g_frame_interval()
603 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_g_mbus_config() local
604 const struct sc2232_mode *mode = sc2232->cur_mode; in sc2232_g_mbus_config()
623 static void sc2232_get_module_inf(struct sc2232 *sc2232, in sc2232_get_module_inf() argument
628 strlcpy(inf->base.module, sc2232->module_name, in sc2232_get_module_inf()
630 strlcpy(inf->base.lens, sc2232->len_name, sizeof(inf->base.lens)); in sc2232_get_module_inf()
633 static int sc2232_set_gain(struct sc2232 *sc2232, u32 total_gain) in sc2232_set_gain() argument
649 ret |= sc2232_write_reg(sc2232->client, 0x3301, SC2232_REG_VALUE_08BIT, 0x0f); in sc2232_set_gain()
650 ret |= sc2232_write_reg(sc2232->client, 0x3632, SC2232_REG_VALUE_08BIT, 0x08); in sc2232_set_gain()
660 ret |= sc2232_write_reg(sc2232->client, 0x3301, SC2232_REG_VALUE_08BIT, 0x20); in sc2232_set_gain()
661 ret |= sc2232_write_reg(sc2232->client, 0x3632, SC2232_REG_VALUE_08BIT, 0x08); in sc2232_set_gain()
671 ret |= sc2232_write_reg(sc2232->client, 0x3301, SC2232_REG_VALUE_08BIT, 0x28); in sc2232_set_gain()
672 ret |= sc2232_write_reg(sc2232->client, 0x3632, SC2232_REG_VALUE_08BIT, 0x08); in sc2232_set_gain()
682 ret |= sc2232_write_reg(sc2232->client, 0x3301, SC2232_REG_VALUE_08BIT, 0x80); in sc2232_set_gain()
683 ret |= sc2232_write_reg(sc2232->client, 0x3632, SC2232_REG_VALUE_08BIT, 0x08); in sc2232_set_gain()
693 ret |= sc2232_write_reg(sc2232->client, 0x3301, SC2232_REG_VALUE_08BIT, 0x80); in sc2232_set_gain()
694 ret |= sc2232_write_reg(sc2232->client, 0x3632, SC2232_REG_VALUE_08BIT, 0x48); in sc2232_set_gain()
703 ret |= sc2232_write_reg(sc2232->client, 0x3301, SC2232_REG_VALUE_08BIT, 0x80); in sc2232_set_gain()
704 ret |= sc2232_write_reg(sc2232->client, 0x3632, SC2232_REG_VALUE_08BIT, 0x48); in sc2232_set_gain()
713 ret |= sc2232_write_reg(sc2232->client, 0x3301, SC2232_REG_VALUE_08BIT, 0x80); in sc2232_set_gain()
714 ret |= sc2232_write_reg(sc2232->client, 0x3632, SC2232_REG_VALUE_08BIT, 0x48); in sc2232_set_gain()
724 ret |= sc2232_write_reg(sc2232->client, 0x3301, SC2232_REG_VALUE_08BIT, 0x80); in sc2232_set_gain()
725 ret |= sc2232_write_reg(sc2232->client, 0x3632, SC2232_REG_VALUE_08BIT, 0x48); in sc2232_set_gain()
728 ret |= sc2232_write_reg(sc2232->client, 0x3812, SC2232_REG_VALUE_08BIT, 0x30); in sc2232_set_gain()
730 …dev_dbg(&sc2232->client->dev, "total_gain:%d again 0x%x, again_fine 0x%x, dgain 0x%x, dgain_fine 0… in sc2232_set_gain()
733 ret |= sc2232_read_reg(sc2232->client, SC2232_REG_AGAIN,SC2232_REG_VALUE_08BIT, &val); in sc2232_set_gain()
734 …ret |= sc2232_write_reg(sc2232->client, SC2232_REG_AGAIN,SC2232_REG_VALUE_08BIT, (val & 0xE3) | (a… in sc2232_set_gain()
735 ret |= sc2232_read_reg(sc2232->client, SC2232_REG_DGAIN,SC2232_REG_VALUE_08BIT, &val); in sc2232_set_gain()
736 …ret |= sc2232_write_reg(sc2232->client, SC2232_REG_DGAIN,SC2232_REG_VALUE_08BIT,(val & 0xF0) | dga… in sc2232_set_gain()
738 ret |= sc2232_write_reg(sc2232->client, SC2232_REG_AGAIN_FINE, SC2232_REG_VALUE_08BIT, again_fine); in sc2232_set_gain()
739 ret |= sc2232_write_reg(sc2232->client, SC2232_REG_DGAIN_FINE, SC2232_REG_VALUE_08BIT, dgain_fine); in sc2232_set_gain()
745 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_ioctl() local
756 sc2232_get_module_inf(sc2232, (struct rkmodule_inf *)arg); in sc2232_ioctl()
761 hdr_cfg->hdr_mode = sc2232->cur_mode->hdr_mode; in sc2232_ioctl()
766 ret = sc2232_write_reg(sc2232->client, SC2232_REG_CTRL_MODE, in sc2232_ioctl()
769 ret = sc2232_write_reg(sc2232->client, SC2232_REG_CTRL_MODE, in sc2232_ioctl()
889 static int __sc2232_start_stream(struct sc2232 *sc2232) in __sc2232_start_stream() argument
893 ret = sc2232_write_array(sc2232->client, sc2232->cur_mode->reg_list); in __sc2232_start_stream()
897 ret = __v4l2_ctrl_handler_setup(&sc2232->ctrl_handler); in __sc2232_start_stream()
902 if (sc2232->has_init_exp && sc2232->cur_mode->hdr_mode != NO_HDR) { in __sc2232_start_stream()
903 ret = sc2232_ioctl(&sc2232->subdev, PREISP_CMD_SET_HDRAE_EXP, in __sc2232_start_stream()
904 &sc2232->init_hdrae_exp); in __sc2232_start_stream()
906 dev_err(&sc2232->client->dev, in __sc2232_start_stream()
912 return sc2232_write_reg(sc2232->client, SC2232_REG_CTRL_MODE, in __sc2232_start_stream()
916 static int __sc2232_stop_stream(struct sc2232 *sc2232) in __sc2232_stop_stream() argument
918 sc2232->has_init_exp = false; in __sc2232_stop_stream()
919 return sc2232_write_reg(sc2232->client, SC2232_REG_CTRL_MODE, in __sc2232_stop_stream()
925 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_s_stream() local
926 struct i2c_client *client = sc2232->client; in sc2232_s_stream()
929 mutex_lock(&sc2232->mutex); in sc2232_s_stream()
931 if (on == sc2232->streaming) in sc2232_s_stream()
941 ret = __sc2232_start_stream(sc2232); in sc2232_s_stream()
948 __sc2232_stop_stream(sc2232); in sc2232_s_stream()
952 sc2232->streaming = on; in sc2232_s_stream()
955 mutex_unlock(&sc2232->mutex); in sc2232_s_stream()
962 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_s_power() local
963 struct i2c_client *client = sc2232->client; in sc2232_s_power()
966 mutex_lock(&sc2232->mutex); in sc2232_s_power()
969 if (sc2232->power_on == !!on) in sc2232_s_power()
979 ret |= sc2232_write_reg(sc2232->client, in sc2232_s_power()
985 sc2232->power_on = true; in sc2232_s_power()
988 sc2232->power_on = false; in sc2232_s_power()
992 mutex_unlock(&sc2232->mutex); in sc2232_s_power()
997 static int __sc2232_power_on(struct sc2232 *sc2232) in __sc2232_power_on() argument
1000 struct device *dev = &sc2232->client->dev; in __sc2232_power_on()
1002 if (!IS_ERR_OR_NULL(sc2232->pins_default)) { in __sc2232_power_on()
1003 ret = pinctrl_select_state(sc2232->pinctrl, in __sc2232_power_on()
1004 sc2232->pins_default); in __sc2232_power_on()
1008 ret = clk_set_rate(sc2232->xvclk, SC2232_XVCLK_FREQ); in __sc2232_power_on()
1011 if (clk_get_rate(sc2232->xvclk) != SC2232_XVCLK_FREQ) in __sc2232_power_on()
1013 ret = clk_prepare_enable(sc2232->xvclk); in __sc2232_power_on()
1018 if (!IS_ERR(sc2232->reset_gpio)) in __sc2232_power_on()
1019 gpiod_set_value_cansleep(sc2232->reset_gpio, 1); in __sc2232_power_on()
1021 ret = regulator_bulk_enable(SC2232_NUM_SUPPLIES, sc2232->supplies); in __sc2232_power_on()
1027 if (!IS_ERR(sc2232->reset_gpio)) in __sc2232_power_on()
1028 gpiod_set_value_cansleep(sc2232->reset_gpio, 0); in __sc2232_power_on()
1031 if (!IS_ERR(sc2232->pwdn_gpio)) in __sc2232_power_on()
1032 gpiod_set_value_cansleep(sc2232->pwdn_gpio, 1); in __sc2232_power_on()
1038 clk_disable_unprepare(sc2232->xvclk); in __sc2232_power_on()
1043 static void __sc2232_power_off(struct sc2232 *sc2232) in __sc2232_power_off() argument
1046 struct device *dev = &sc2232->client->dev; in __sc2232_power_off()
1048 if (!IS_ERR(sc2232->pwdn_gpio)) in __sc2232_power_off()
1049 gpiod_set_value_cansleep(sc2232->pwdn_gpio, 0); in __sc2232_power_off()
1050 clk_disable_unprepare(sc2232->xvclk); in __sc2232_power_off()
1051 if (!IS_ERR(sc2232->reset_gpio)) in __sc2232_power_off()
1052 gpiod_set_value_cansleep(sc2232->reset_gpio, 1); in __sc2232_power_off()
1053 if (!IS_ERR_OR_NULL(sc2232->pins_sleep)) { in __sc2232_power_off()
1054 ret = pinctrl_select_state(sc2232->pinctrl, in __sc2232_power_off()
1055 sc2232->pins_sleep); in __sc2232_power_off()
1059 regulator_bulk_disable(SC2232_NUM_SUPPLIES, sc2232->supplies); in __sc2232_power_off()
1066 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_runtime_resume() local
1068 return __sc2232_power_on(sc2232); in sc2232_runtime_resume()
1075 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_runtime_suspend() local
1077 __sc2232_power_off(sc2232); in sc2232_runtime_suspend()
1085 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_open() local
1090 mutex_lock(&sc2232->mutex); in sc2232_open()
1097 mutex_unlock(&sc2232->mutex); in sc2232_open()
1108 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_enum_frame_interval() local
1110 if (fie->index >= sc2232->cfg_num) in sc2232_enum_frame_interval()
1160 static void sc2232_modify_fps_info(struct sc2232 *sc2232) in sc2232_modify_fps_info() argument
1162 const struct sc2232_mode *mode = sc2232->cur_mode; in sc2232_modify_fps_info()
1164 sc2232->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def / in sc2232_modify_fps_info()
1165 sc2232->cur_vts; in sc2232_modify_fps_info()
1170 struct sc2232 *sc2232 = container_of(ctrl->handler, in sc2232_set_ctrl() local
1171 struct sc2232, ctrl_handler); in sc2232_set_ctrl()
1172 struct i2c_client *client = sc2232->client; in sc2232_set_ctrl()
1181 max = sc2232->cur_mode->height + ctrl->val - 2; in sc2232_set_ctrl()
1182 __v4l2_ctrl_modify_range(sc2232->exposure, in sc2232_set_ctrl()
1183 sc2232->exposure->minimum, max, in sc2232_set_ctrl()
1184 sc2232->exposure->step, in sc2232_set_ctrl()
1185 sc2232->exposure->default_value); in sc2232_set_ctrl()
1194 if (sc2232->cur_mode->hdr_mode != NO_HDR) in sc2232_set_ctrl()
1197 ret = sc2232_write_reg(sc2232->client, in sc2232_set_ctrl()
1201 ret |= sc2232_write_reg(sc2232->client, in sc2232_set_ctrl()
1205 ret |= sc2232_write_reg(sc2232->client, in sc2232_set_ctrl()
1212 if (sc2232->cur_mode->hdr_mode != NO_HDR) in sc2232_set_ctrl()
1214 ret = sc2232_set_gain(sc2232, ctrl->val); in sc2232_set_ctrl()
1217 ret = sc2232_write_reg(sc2232->client, SC2232_REG_VTS, in sc2232_set_ctrl()
1219 ctrl->val + sc2232->cur_mode->height); in sc2232_set_ctrl()
1221 sc2232->cur_vts = ctrl->val + sc2232->cur_mode->height; in sc2232_set_ctrl()
1222 sc2232_modify_fps_info(sc2232); in sc2232_set_ctrl()
1229 ret = sc2232_read_reg(sc2232->client, SC2232_FLIP_REG, in sc2232_set_ctrl()
1237 ret |= sc2232_write_reg(sc2232->client, SC2232_FLIP_REG, in sc2232_set_ctrl()
1241 ret = sc2232_read_reg(sc2232->client, SC2232_FLIP_REG, in sc2232_set_ctrl()
1249 ret |= sc2232_write_reg(sc2232->client, SC2232_FLIP_REG, in sc2232_set_ctrl()
1267 static int sc2232_initialize_controls(struct sc2232 *sc2232) in sc2232_initialize_controls() argument
1276 handler = &sc2232->ctrl_handler; in sc2232_initialize_controls()
1277 mode = sc2232->cur_mode; in sc2232_initialize_controls()
1281 handler->lock = &sc2232->mutex; in sc2232_initialize_controls()
1283 sc2232->link_freq = v4l2_ctrl_new_int_menu(handler, NULL, in sc2232_initialize_controls()
1287 __v4l2_ctrl_s_ctrl(sc2232->link_freq, mode->mipi_freq_idx); in sc2232_initialize_controls()
1291 sc2232->pixel_rate = v4l2_ctrl_new_std(handler, NULL, in sc2232_initialize_controls()
1296 sc2232->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in sc2232_initialize_controls()
1298 if (sc2232->hblank) in sc2232_initialize_controls()
1299 sc2232->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in sc2232_initialize_controls()
1302 sc2232->vblank = v4l2_ctrl_new_std(handler, &sc2232_ctrl_ops, in sc2232_initialize_controls()
1308 sc2232->exposure = v4l2_ctrl_new_std(handler, &sc2232_ctrl_ops, in sc2232_initialize_controls()
1313 sc2232->anal_gain = v4l2_ctrl_new_std(handler, &sc2232_ctrl_ops, in sc2232_initialize_controls()
1323 dev_err(&sc2232->client->dev, in sc2232_initialize_controls()
1328 sc2232->subdev.ctrl_handler = handler; in sc2232_initialize_controls()
1329 sc2232->has_init_exp = false; in sc2232_initialize_controls()
1330 sc2232->cur_vts = mode->vts_def; in sc2232_initialize_controls()
1331 sc2232->cur_fps = mode->max_fps; in sc2232_initialize_controls()
1341 static int sc2232_check_sensor_id(struct sc2232 *sc2232, in sc2232_check_sensor_id() argument
1344 struct device *dev = &sc2232->client->dev; in sc2232_check_sensor_id()
1359 static int sc2232_configure_regulators(struct sc2232 *sc2232) in sc2232_configure_regulators() argument
1364 sc2232->supplies[i].supply = sc2232_supply_names[i]; in sc2232_configure_regulators()
1366 return devm_regulator_bulk_get(&sc2232->client->dev, in sc2232_configure_regulators()
1368 sc2232->supplies); in sc2232_configure_regulators()
1376 struct sc2232 *sc2232; in sc2232_probe() local
1387 sc2232 = devm_kzalloc(dev, sizeof(*sc2232), GFP_KERNEL); in sc2232_probe()
1388 if (!sc2232) in sc2232_probe()
1392 &sc2232->module_index); in sc2232_probe()
1394 &sc2232->module_facing); in sc2232_probe()
1396 &sc2232->module_name); in sc2232_probe()
1398 &sc2232->len_name); in sc2232_probe()
1412 sc2232->cfg_num = ARRAY_SIZE(supported_modes); in sc2232_probe()
1413 for (i = 0; i < sc2232->cfg_num; i++) { in sc2232_probe()
1415 sc2232->cur_mode = &supported_modes[i]; in sc2232_probe()
1419 sc2232->client = client; in sc2232_probe()
1421 sc2232->xvclk = devm_clk_get(dev, "xvclk"); in sc2232_probe()
1422 if (IS_ERR(sc2232->xvclk)) { in sc2232_probe()
1427 sc2232->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in sc2232_probe()
1428 if (IS_ERR(sc2232->reset_gpio)) in sc2232_probe()
1431 sc2232->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in sc2232_probe()
1432 if (IS_ERR(sc2232->pwdn_gpio)) in sc2232_probe()
1435 sc2232->pinctrl = devm_pinctrl_get(dev); in sc2232_probe()
1436 if (!IS_ERR(sc2232->pinctrl)) { in sc2232_probe()
1437 sc2232->pins_default = in sc2232_probe()
1438 pinctrl_lookup_state(sc2232->pinctrl, in sc2232_probe()
1440 if (IS_ERR(sc2232->pins_default)) in sc2232_probe()
1443 sc2232->pins_sleep = in sc2232_probe()
1444 pinctrl_lookup_state(sc2232->pinctrl, in sc2232_probe()
1446 if (IS_ERR(sc2232->pins_sleep)) in sc2232_probe()
1452 ret = sc2232_configure_regulators(sc2232); in sc2232_probe()
1458 mutex_init(&sc2232->mutex); in sc2232_probe()
1460 sd = &sc2232->subdev; in sc2232_probe()
1462 ret = sc2232_initialize_controls(sc2232); in sc2232_probe()
1466 ret = __sc2232_power_on(sc2232); in sc2232_probe()
1470 ret = sc2232_check_sensor_id(sc2232, client); in sc2232_probe()
1479 sc2232->pad.flags = MEDIA_PAD_FL_SOURCE; in sc2232_probe()
1481 ret = media_entity_pads_init(&sd->entity, 1, &sc2232->pad); in sc2232_probe()
1487 if (strcmp(sc2232->module_facing, "back") == 0) in sc2232_probe()
1493 sc2232->module_index, facing, in sc2232_probe()
1514 __sc2232_power_off(sc2232); in sc2232_probe()
1516 v4l2_ctrl_handler_free(&sc2232->ctrl_handler); in sc2232_probe()
1518 mutex_destroy(&sc2232->mutex); in sc2232_probe()
1526 struct sc2232 *sc2232 = to_sc2232(sd); in sc2232_remove() local
1532 v4l2_ctrl_handler_free(&sc2232->ctrl_handler); in sc2232_remove()
1533 mutex_destroy(&sc2232->mutex); in sc2232_remove()
1537 __sc2232_power_off(sc2232); in sc2232_remove()