Lines Matching refs:ov02b10
119 struct ov02b10 { struct
156 #define to_ov02b10(sd) container_of(sd, struct ov02b10, subdev) argument
301 static int __ov02b10_power_on(struct ov02b10 *ov02b10);
303 static int ov02b10_check_sensor_id(struct ov02b10 *ov02b10,
388 ov02b10_find_best_fit(struct ov02b10 *ov02b10, struct v4l2_subdev_format *fmt) in ov02b10_find_best_fit() argument
396 for (i = 0; i < ov02b10->cfg_num; i++) { in ov02b10_find_best_fit()
412 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_set_fmt() local
418 mutex_lock(&ov02b10->mutex); in ov02b10_set_fmt()
420 mode = ov02b10_find_best_fit(ov02b10, fmt); in ov02b10_set_fmt()
429 mutex_unlock(&ov02b10->mutex); in ov02b10_set_fmt()
433 ov02b10->cur_mode = mode; in ov02b10_set_fmt()
435 __v4l2_ctrl_modify_range(ov02b10->hblank, h_blank, in ov02b10_set_fmt()
440 __v4l2_ctrl_modify_range(ov02b10->vblank, vblank_def, in ov02b10_set_fmt()
449 __v4l2_ctrl_s_ctrl_int64(ov02b10->pixel_rate, in ov02b10_set_fmt()
451 __v4l2_ctrl_s_ctrl(ov02b10->link_freq, in ov02b10_set_fmt()
455 mutex_unlock(&ov02b10->mutex); in ov02b10_set_fmt()
464 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_get_fmt() local
465 const struct ov02b10_mode *mode = ov02b10->cur_mode; in ov02b10_get_fmt()
467 mutex_lock(&ov02b10->mutex); in ov02b10_get_fmt()
472 mutex_unlock(&ov02b10->mutex); in ov02b10_get_fmt()
485 mutex_unlock(&ov02b10->mutex); in ov02b10_get_fmt()
494 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_enum_mbus_code() local
498 code->code = ov02b10->cur_mode->bus_fmt; in ov02b10_enum_mbus_code()
507 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_enum_frame_sizes() local
509 if (fse->index >= ov02b10->cfg_num) in ov02b10_enum_frame_sizes()
526 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_g_frame_interval() local
527 const struct ov02b10_mode *mode = ov02b10->cur_mode; in ov02b10_g_frame_interval()
537 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_g_mbus_config() local
538 const struct ov02b10_mode *mode = ov02b10->cur_mode; in ov02b10_g_mbus_config()
557 static void ov02b10_get_module_inf(struct ov02b10 *ov02b10, in ov02b10_get_module_inf() argument
562 strlcpy(inf->base.module, ov02b10->module_name, in ov02b10_get_module_inf()
564 strlcpy(inf->base.lens, ov02b10->len_name, sizeof(inf->base.lens)); in ov02b10_get_module_inf()
569 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_ioctl() local
584 ov02b10_get_module_inf(ov02b10, (struct rkmodule_inf *)arg); in ov02b10_ioctl()
589 hdr_cfg->hdr_mode = ov02b10->cur_mode->hdr_mode; in ov02b10_ioctl()
596 ret = ov02b10_write_reg(ov02b10->client, OV02B10_REG_CTRL_MODE, in ov02b10_ioctl()
599 ret = ov02b10_write_reg(ov02b10->client, OV02B10_REG_CTRL_MODE, in ov02b10_ioctl()
719 static int __ov02b10_start_stream(struct ov02b10 *ov02b10) in __ov02b10_start_stream() argument
723 ret = ov02b10_write_array(ov02b10->client, ov02b10->cur_mode->reg_list); in __ov02b10_start_stream()
728 ret = __v4l2_ctrl_handler_setup(&ov02b10->ctrl_handler); in __ov02b10_start_stream()
731 if (ov02b10->has_init_exp && ov02b10->cur_mode->hdr_mode != NO_HDR) { in __ov02b10_start_stream()
732 ret = ov02b10_ioctl(&ov02b10->subdev, PREISP_CMD_SET_HDRAE_EXP, in __ov02b10_start_stream()
733 &ov02b10->init_hdrae_exp); in __ov02b10_start_stream()
735 dev_err(&ov02b10->client->dev, in __ov02b10_start_stream()
740 return ov02b10_write_reg(ov02b10->client, OV02B10_REG_CTRL_MODE, OV02B10_MODE_STREAMING); in __ov02b10_start_stream()
743 static int __ov02b10_stop_stream(struct ov02b10 *ov02b10) in __ov02b10_stop_stream() argument
745 ov02b10->has_init_exp = false; in __ov02b10_stop_stream()
746 return ov02b10_write_reg(ov02b10->client, OV02B10_REG_CTRL_MODE, OV02B10_MODE_SW_STANDBY); in __ov02b10_stop_stream()
751 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_s_stream() local
752 struct i2c_client *client = ov02b10->client; in ov02b10_s_stream()
755 mutex_lock(&ov02b10->mutex); in ov02b10_s_stream()
757 if (on == ov02b10->streaming) in ov02b10_s_stream()
767 ret = __ov02b10_start_stream(ov02b10); in ov02b10_s_stream()
774 __ov02b10_stop_stream(ov02b10); in ov02b10_s_stream()
778 ov02b10->streaming = on; in ov02b10_s_stream()
781 mutex_unlock(&ov02b10->mutex); in ov02b10_s_stream()
788 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_s_power() local
789 struct i2c_client *client = ov02b10->client; in ov02b10_s_power()
792 mutex_lock(&ov02b10->mutex); in ov02b10_s_power()
795 if (ov02b10->power_on == !!on) in ov02b10_s_power()
805 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_s_power()
810 ov02b10->power_on = true; in ov02b10_s_power()
813 ov02b10->power_on = false; in ov02b10_s_power()
817 mutex_unlock(&ov02b10->mutex); in ov02b10_s_power()
822 static int ov02b10_enable_regulators(struct ov02b10 *ov02b10, in ov02b10_enable_regulators() argument
827 struct device *dev = &ov02b10->client->dev; in ov02b10_enable_regulators()
847 static int __ov02b10_power_on(struct ov02b10 *ov02b10) in __ov02b10_power_on() argument
850 struct device *dev = &ov02b10->client->dev; in __ov02b10_power_on()
852 if (!IS_ERR_OR_NULL(ov02b10->pins_default)) { in __ov02b10_power_on()
853 ret = pinctrl_select_state(ov02b10->pinctrl, in __ov02b10_power_on()
854 ov02b10->pins_default); in __ov02b10_power_on()
858 ret = clk_set_rate(ov02b10->xvclk, OV02B10_XVCLK_FREQ); in __ov02b10_power_on()
861 if (clk_get_rate(ov02b10->xvclk) != OV02B10_XVCLK_FREQ) in __ov02b10_power_on()
864 if (!IS_ERR(ov02b10->pwdn_gpio)) in __ov02b10_power_on()
865 gpiod_direction_output(ov02b10->pwdn_gpio, 1); in __ov02b10_power_on()
867 if (!IS_ERR(ov02b10->reset_gpio)) in __ov02b10_power_on()
868 gpiod_direction_output(ov02b10->reset_gpio, 1); in __ov02b10_power_on()
870 ret = ov02b10_enable_regulators(ov02b10, ov02b10->supplies); in __ov02b10_power_on()
876 ret = clk_prepare_enable(ov02b10->xvclk); in __ov02b10_power_on()
884 if (!IS_ERR(ov02b10->pwdn_gpio)) in __ov02b10_power_on()
885 gpiod_direction_output(ov02b10->pwdn_gpio, 0); in __ov02b10_power_on()
889 if (!IS_ERR(ov02b10->reset_gpio)) in __ov02b10_power_on()
890 gpiod_direction_output(ov02b10->reset_gpio, 0); in __ov02b10_power_on()
897 clk_disable_unprepare(ov02b10->xvclk); in __ov02b10_power_on()
902 static void __ov02b10_power_off(struct ov02b10 *ov02b10) in __ov02b10_power_off() argument
905 struct device *dev = &ov02b10->client->dev; in __ov02b10_power_off()
907 if (!IS_ERR(ov02b10->reset_gpio)) in __ov02b10_power_off()
908 gpiod_direction_output(ov02b10->reset_gpio, 1); in __ov02b10_power_off()
910 clk_disable_unprepare(ov02b10->xvclk); in __ov02b10_power_off()
912 if (!IS_ERR(ov02b10->pwdn_gpio)) in __ov02b10_power_off()
913 gpiod_direction_output(ov02b10->pwdn_gpio, 1); in __ov02b10_power_off()
915 if (!IS_ERR_OR_NULL(ov02b10->pins_sleep)) { in __ov02b10_power_off()
916 ret = pinctrl_select_state(ov02b10->pinctrl, in __ov02b10_power_off()
917 ov02b10->pins_sleep); in __ov02b10_power_off()
921 regulator_bulk_disable(OV02B10_NUM_SUPPLIES, ov02b10->supplies); in __ov02b10_power_off()
928 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_runtime_resume() local
930 return __ov02b10_power_on(ov02b10); in ov02b10_runtime_resume()
937 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_runtime_suspend() local
939 __ov02b10_power_off(ov02b10); in ov02b10_runtime_suspend()
947 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_open() local
952 mutex_lock(&ov02b10->mutex); in ov02b10_open()
959 mutex_unlock(&ov02b10->mutex); in ov02b10_open()
970 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_enum_frame_interval() local
972 if (fie->index >= ov02b10->cfg_num) in ov02b10_enum_frame_interval()
1024 struct ov02b10 *ov02b10 = container_of(ctrl->handler, in ov02b10_set_ctrl() local
1025 struct ov02b10, ctrl_handler); in ov02b10_set_ctrl()
1026 struct i2c_client *client = ov02b10->client; in ov02b10_set_ctrl()
1035 max = ov02b10->cur_mode->height + ctrl->val - 7; in ov02b10_set_ctrl()
1036 __v4l2_ctrl_modify_range(ov02b10->exposure, in ov02b10_set_ctrl()
1037 ov02b10->exposure->minimum, max, in ov02b10_set_ctrl()
1038 ov02b10->exposure->step, in ov02b10_set_ctrl()
1039 ov02b10->exposure->default_value); in ov02b10_set_ctrl()
1048 ret = ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1050 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1052 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1054 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1066 ret = ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1068 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1070 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1072 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1074 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1081 ret = ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1083 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1085 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1087 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1095 ov02b10->flip |= MIRROR_BIT_MASK; in ov02b10_set_ctrl()
1097 ov02b10->flip &= ~MIRROR_BIT_MASK; in ov02b10_set_ctrl()
1099 ret = ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1101 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1102 OV02B10_FLIP_REG, ov02b10->flip); in ov02b10_set_ctrl()
1103 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1105 dev_dbg(&client->dev, "set hflip 0x%x\n", ov02b10->flip); in ov02b10_set_ctrl()
1109 ov02b10->flip |= FLIP_BIT_MASK; in ov02b10_set_ctrl()
1111 ov02b10->flip &= ~FLIP_BIT_MASK; in ov02b10_set_ctrl()
1113 ret = ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1115 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1116 OV02B10_FLIP_REG, ov02b10->flip); in ov02b10_set_ctrl()
1117 ret |= ov02b10_write_reg(ov02b10->client, in ov02b10_set_ctrl()
1119 dev_dbg(&client->dev, "set vflip 0x%x\n", ov02b10->flip); in ov02b10_set_ctrl()
1135 static int ov02b10_initialize_controls(struct ov02b10 *ov02b10) in ov02b10_initialize_controls() argument
1145 handler = &ov02b10->ctrl_handler; in ov02b10_initialize_controls()
1146 mode = ov02b10->cur_mode; in ov02b10_initialize_controls()
1150 handler->lock = &ov02b10->mutex; in ov02b10_initialize_controls()
1152 ov02b10->link_freq = v4l2_ctrl_new_int_menu(handler, NULL, in ov02b10_initialize_controls()
1156 if (ov02b10->cur_mode->bus_fmt == MEDIA_BUS_FMT_SBGGR10_1X10) { in ov02b10_initialize_controls()
1161 ov02b10->pixel_rate = v4l2_ctrl_new_std(handler, NULL, in ov02b10_initialize_controls()
1166 __v4l2_ctrl_s_ctrl(ov02b10->link_freq, in ov02b10_initialize_controls()
1170 ov02b10->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in ov02b10_initialize_controls()
1172 if (ov02b10->hblank) in ov02b10_initialize_controls()
1173 ov02b10->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov02b10_initialize_controls()
1177 ov02b10->vblank = v4l2_ctrl_new_std(handler, &ov02b10_ctrl_ops, in ov02b10_initialize_controls()
1183 ov02b10->exposure = v4l2_ctrl_new_std(handler, &ov02b10_ctrl_ops, in ov02b10_initialize_controls()
1188 ov02b10->anal_gain = v4l2_ctrl_new_std(handler, &ov02b10_ctrl_ops, in ov02b10_initialize_controls()
1193 ov02b10->h_flip = v4l2_ctrl_new_std(handler, &ov02b10_ctrl_ops, in ov02b10_initialize_controls()
1196 ov02b10->v_flip = v4l2_ctrl_new_std(handler, &ov02b10_ctrl_ops, in ov02b10_initialize_controls()
1198 ov02b10->flip = 0; in ov02b10_initialize_controls()
1201 dev_err(&ov02b10->client->dev, in ov02b10_initialize_controls()
1206 ov02b10->subdev.ctrl_handler = handler; in ov02b10_initialize_controls()
1207 ov02b10->has_init_exp = false; in ov02b10_initialize_controls()
1217 static int ov02b10_check_sensor_id(struct ov02b10 *ov02b10, in ov02b10_check_sensor_id() argument
1220 struct device *dev = &ov02b10->client->dev; in ov02b10_check_sensor_id()
1236 static int ov02b10_configure_regulators(struct ov02b10 *ov02b10) in ov02b10_configure_regulators() argument
1241 ov02b10->supplies[i].supply = OV02B10_supply_names[i]; in ov02b10_configure_regulators()
1243 return devm_regulator_bulk_get(&ov02b10->client->dev, in ov02b10_configure_regulators()
1245 ov02b10->supplies); in ov02b10_configure_regulators()
1253 struct ov02b10 *ov02b10; in ov02b10_probe() local
1264 ov02b10 = devm_kzalloc(dev, sizeof(*ov02b10), GFP_KERNEL); in ov02b10_probe()
1265 if (!ov02b10) in ov02b10_probe()
1269 &ov02b10->module_index); in ov02b10_probe()
1271 &ov02b10->module_facing); in ov02b10_probe()
1273 &ov02b10->module_name); in ov02b10_probe()
1275 &ov02b10->len_name); in ov02b10_probe()
1287 ov02b10->cfg_num = ARRAY_SIZE(supported_modes); in ov02b10_probe()
1288 for (i = 0; i < ov02b10->cfg_num; i++) { in ov02b10_probe()
1290 ov02b10->cur_mode = &supported_modes[i]; in ov02b10_probe()
1294 ov02b10->client = client; in ov02b10_probe()
1296 ov02b10->xvclk = devm_clk_get(dev, "xvclk"); in ov02b10_probe()
1297 if (IS_ERR(ov02b10->xvclk)) { in ov02b10_probe()
1302 ov02b10->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); in ov02b10_probe()
1303 if (IS_ERR(ov02b10->reset_gpio)) in ov02b10_probe()
1306 ov02b10->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS); in ov02b10_probe()
1307 if (IS_ERR(ov02b10->pwdn_gpio)) in ov02b10_probe()
1310 ov02b10->pinctrl = devm_pinctrl_get(dev); in ov02b10_probe()
1311 if (!IS_ERR(ov02b10->pinctrl)) { in ov02b10_probe()
1312 ov02b10->pins_default = in ov02b10_probe()
1313 pinctrl_lookup_state(ov02b10->pinctrl, in ov02b10_probe()
1315 if (IS_ERR(ov02b10->pins_default)) in ov02b10_probe()
1318 ov02b10->pins_sleep = in ov02b10_probe()
1319 pinctrl_lookup_state(ov02b10->pinctrl, in ov02b10_probe()
1321 if (IS_ERR(ov02b10->pins_sleep)) in ov02b10_probe()
1327 ret = ov02b10_configure_regulators(ov02b10); in ov02b10_probe()
1333 mutex_init(&ov02b10->mutex); in ov02b10_probe()
1335 sd = &ov02b10->subdev; in ov02b10_probe()
1337 ret = ov02b10_initialize_controls(ov02b10); in ov02b10_probe()
1341 ret = __ov02b10_power_on(ov02b10); in ov02b10_probe()
1345 ret = ov02b10_check_sensor_id(ov02b10, client); in ov02b10_probe()
1354 ov02b10->pad.flags = MEDIA_PAD_FL_SOURCE; in ov02b10_probe()
1356 ret = media_entity_pads_init(&sd->entity, 1, &ov02b10->pad); in ov02b10_probe()
1362 if (strcmp(ov02b10->module_facing, "back") == 0) in ov02b10_probe()
1368 ov02b10->module_index, facing, in ov02b10_probe()
1387 __ov02b10_power_off(ov02b10); in ov02b10_probe()
1389 v4l2_ctrl_handler_free(&ov02b10->ctrl_handler); in ov02b10_probe()
1391 mutex_destroy(&ov02b10->mutex); in ov02b10_probe()
1399 struct ov02b10 *ov02b10 = to_ov02b10(sd); in ov02b10_remove() local
1405 v4l2_ctrl_handler_free(&ov02b10->ctrl_handler); in ov02b10_remove()
1406 mutex_destroy(&ov02b10->mutex); in ov02b10_remove()
1410 __ov02b10_power_off(ov02b10); in ov02b10_remove()