Lines Matching refs:OV4686

124 struct OV4686 {  struct
156 #define to_OV4686(sd) container_of(sd, struct OV4686, subdev) argument
608 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_set_fmt() local
612 mutex_lock(&OV4686->mutex); in OV4686_set_fmt()
623 mutex_unlock(&OV4686->mutex); in OV4686_set_fmt()
627 OV4686->cur_mode = mode; in OV4686_set_fmt()
629 __v4l2_ctrl_modify_range(OV4686->hblank, h_blank, in OV4686_set_fmt()
632 __v4l2_ctrl_modify_range(OV4686->vblank, vblank_def, in OV4686_set_fmt()
637 mutex_unlock(&OV4686->mutex); in OV4686_set_fmt()
646 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_get_fmt() local
647 const struct OV4686_mode *mode = OV4686->cur_mode; in OV4686_get_fmt()
649 mutex_lock(&OV4686->mutex); in OV4686_get_fmt()
654 mutex_unlock(&OV4686->mutex); in OV4686_get_fmt()
668 mutex_unlock(&OV4686->mutex); in OV4686_get_fmt()
702 static int OV4686_enable_test_pattern(struct OV4686 *OV4686, u32 pattern) in OV4686_enable_test_pattern() argument
711 return OV4686_write_reg(OV4686->client, OV4686_REG_TEST_PATTERN, in OV4686_enable_test_pattern()
718 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_g_frame_interval() local
719 const struct OV4686_mode *mode = OV4686->cur_mode; in OV4686_g_frame_interval()
729 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_g_mbus_config() local
730 const struct OV4686_mode *mode = OV4686->cur_mode; in OV4686_g_mbus_config()
746 static void OV4686_get_module_inf(struct OV4686 *OV4686, in OV4686_get_module_inf() argument
751 strlcpy(inf->base.module, OV4686->module_name, in OV4686_get_module_inf()
753 strlcpy(inf->base.lens, OV4686->len_name, sizeof(inf->base.lens)); in OV4686_get_module_inf()
756 static int OV4686_set_hdrae(struct OV4686 *OV4686, in OV4686_set_hdrae() argument
767 if (!OV4686->has_init_exp && !OV4686->streaming) { in OV4686_set_hdrae()
768 OV4686->init_hdrae_exp = *ae; in OV4686_set_hdrae()
769 OV4686->has_init_exp = true; in OV4686_set_hdrae()
770 dev_dbg(&OV4686->client->dev, "OV4686 don't stream, record exp for hdr!\n"); in OV4686_set_hdrae()
774 dev_dbg(&OV4686->client->dev, in OV4686_set_hdrae()
785 if (OV4686->cur_mode->hdr_mode == HDR_X2) { in OV4686_set_hdrae()
792 ret = OV4686_write_reg(OV4686->client, OV4686_GROUP_UPDATE_ADDRESS, in OV4686_set_hdrae()
795 ret |= OV4686_write_reg(OV4686->client, OV4686_REG_L_GAIN, in OV4686_set_hdrae()
797 ret |= OV4686_write_reg(OV4686->client, OV4686_REG_L_EXP, in OV4686_set_hdrae()
799 ret |= OV4686_write_reg(OV4686->client, OV4686_REG_M_GAIN, in OV4686_set_hdrae()
801 ret |= OV4686_write_reg(OV4686->client, OV4686_REG_M_EXP, in OV4686_set_hdrae()
803 if (OV4686->cur_mode->hdr_mode == HDR_X3) { in OV4686_set_hdrae()
804 ret |= OV4686_write_reg(OV4686->client, OV4686_REG_S_GAIN, in OV4686_set_hdrae()
806 ret |= OV4686_write_reg(OV4686->client, OV4686_REG_S_EXP, in OV4686_set_hdrae()
809 ret |= OV4686_write_reg(OV4686->client, OV4686_GROUP_UPDATE_ADDRESS, in OV4686_set_hdrae()
811 ret |= OV4686_write_reg(OV4686->client, OV4686_GROUP_UPDATE_ADDRESS, in OV4686_set_hdrae()
818 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_ioctl() local
826 OV4686_get_module_inf(OV4686, (struct rkmodule_inf *)arg); in OV4686_ioctl()
831 hdr->hdr_mode = OV4686->cur_mode->hdr_mode; in OV4686_ioctl()
835 w = OV4686->cur_mode->width; in OV4686_ioctl()
836 h = OV4686->cur_mode->height; in OV4686_ioctl()
841 OV4686->cur_mode = &supported_modes[i]; in OV4686_ioctl()
846 dev_err(&OV4686->client->dev, in OV4686_ioctl()
851 w = OV4686->cur_mode->hts_def - OV4686->cur_mode->width; in OV4686_ioctl()
852 h = OV4686->cur_mode->vts_def - OV4686->cur_mode->height; in OV4686_ioctl()
853 __v4l2_ctrl_modify_range(OV4686->hblank, w, w, 1, w); in OV4686_ioctl()
854 __v4l2_ctrl_modify_range(OV4686->vblank, h, in OV4686_ioctl()
855 OV4686_VTS_MAX - OV4686->cur_mode->height, 1, h); in OV4686_ioctl()
859 return OV4686_set_hdrae(OV4686, arg); in OV4686_ioctl()
865 ret = OV4686_write_reg(OV4686->client, OV4686_REG_CTRL_MODE, in OV4686_ioctl()
868 ret = OV4686_write_reg(OV4686->client, OV4686_REG_CTRL_MODE, in OV4686_ioctl()
966 static int __OV4686_start_stream(struct OV4686 *OV4686) in __OV4686_start_stream() argument
970 ret = OV4686_write_array(OV4686->client, OV4686_2688x1520_regs); in __OV4686_start_stream()
971 ret |= OV4686_write_array(OV4686->client, OV4686->cur_mode->reg_list); in __OV4686_start_stream()
976 ret = __v4l2_ctrl_handler_setup(&OV4686->ctrl_handler); in __OV4686_start_stream()
979 if (OV4686->has_init_exp && OV4686->cur_mode->hdr_mode != NO_HDR) { in __OV4686_start_stream()
980 ret = OV4686_ioctl(&OV4686->subdev, in __OV4686_start_stream()
982 &OV4686->init_hdrae_exp); in __OV4686_start_stream()
984 dev_err(&OV4686->client->dev, in __OV4686_start_stream()
990 return OV4686_write_reg(OV4686->client, OV4686_REG_CTRL_MODE, in __OV4686_start_stream()
994 static int __OV4686_stop_stream(struct OV4686 *OV4686) in __OV4686_stop_stream() argument
996 OV4686->has_init_exp = false; in __OV4686_stop_stream()
997 return OV4686_write_reg(OV4686->client, OV4686_REG_CTRL_MODE, in __OV4686_stop_stream()
1003 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_s_stream() local
1004 struct i2c_client *client = OV4686->client; in OV4686_s_stream()
1007 mutex_lock(&OV4686->mutex); in OV4686_s_stream()
1009 if (on == OV4686->streaming) in OV4686_s_stream()
1019 ret = __OV4686_start_stream(OV4686); in OV4686_s_stream()
1026 __OV4686_stop_stream(OV4686); in OV4686_s_stream()
1030 OV4686->streaming = on; in OV4686_s_stream()
1033 mutex_unlock(&OV4686->mutex); in OV4686_s_stream()
1040 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_s_power() local
1041 struct i2c_client *client = OV4686->client; in OV4686_s_power()
1044 mutex_lock(&OV4686->mutex); in OV4686_s_power()
1047 if (OV4686->power_on == !!on) in OV4686_s_power()
1057 ret = OV4686_write_array(OV4686->client, OV4686_global_regs); in OV4686_s_power()
1064 OV4686->power_on = true; in OV4686_s_power()
1067 OV4686->power_on = false; in OV4686_s_power()
1071 mutex_unlock(&OV4686->mutex); in OV4686_s_power()
1082 static int __OV4686_power_on(struct OV4686 *OV4686) in __OV4686_power_on() argument
1086 struct device *dev = &OV4686->client->dev; in __OV4686_power_on()
1088 if (!IS_ERR_OR_NULL(OV4686->pins_default)) { in __OV4686_power_on()
1089 ret = pinctrl_select_state(OV4686->pinctrl, in __OV4686_power_on()
1090 OV4686->pins_default); in __OV4686_power_on()
1094 ret = clk_set_rate(OV4686->xvclk, OV4686_XVCLK_FREQ); in __OV4686_power_on()
1097 if (clk_get_rate(OV4686->xvclk) != OV4686_XVCLK_FREQ) in __OV4686_power_on()
1099 ret = clk_prepare_enable(OV4686->xvclk); in __OV4686_power_on()
1104 if (!IS_ERR(OV4686->reset_gpio)) in __OV4686_power_on()
1105 gpiod_set_value_cansleep(OV4686->reset_gpio, 0); in __OV4686_power_on()
1107 ret = regulator_bulk_enable(OV4686_NUM_SUPPLIES, OV4686->supplies); in __OV4686_power_on()
1113 if (!IS_ERR(OV4686->reset_gpio)) in __OV4686_power_on()
1114 gpiod_set_value_cansleep(OV4686->reset_gpio, 1); in __OV4686_power_on()
1117 if (!IS_ERR(OV4686->pwdn_gpio)) in __OV4686_power_on()
1118 gpiod_set_value_cansleep(OV4686->pwdn_gpio, 1); in __OV4686_power_on()
1127 clk_disable_unprepare(OV4686->xvclk); in __OV4686_power_on()
1132 static void __OV4686_power_off(struct OV4686 *OV4686) in __OV4686_power_off() argument
1135 struct device *dev = &OV4686->client->dev; in __OV4686_power_off()
1137 if (!IS_ERR(OV4686->pwdn_gpio)) in __OV4686_power_off()
1138 gpiod_set_value_cansleep(OV4686->pwdn_gpio, 0); in __OV4686_power_off()
1139 clk_disable_unprepare(OV4686->xvclk); in __OV4686_power_off()
1140 if (!IS_ERR(OV4686->reset_gpio)) in __OV4686_power_off()
1141 gpiod_set_value_cansleep(OV4686->reset_gpio, 0); in __OV4686_power_off()
1142 if (!IS_ERR_OR_NULL(OV4686->pins_sleep)) { in __OV4686_power_off()
1143 ret = pinctrl_select_state(OV4686->pinctrl, in __OV4686_power_off()
1144 OV4686->pins_sleep); in __OV4686_power_off()
1148 regulator_bulk_disable(OV4686_NUM_SUPPLIES, OV4686->supplies); in __OV4686_power_off()
1155 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_runtime_resume() local
1157 return __OV4686_power_on(OV4686); in OV4686_runtime_resume()
1164 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_runtime_suspend() local
1166 __OV4686_power_off(OV4686); in OV4686_runtime_suspend()
1174 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_open() local
1179 mutex_lock(&OV4686->mutex); in OV4686_open()
1186 mutex_unlock(&OV4686->mutex); in OV4686_open()
1249 struct OV4686 *OV4686 = container_of(ctrl->handler, in OV4686_set_ctrl() local
1250 struct OV4686, ctrl_handler); in OV4686_set_ctrl()
1251 struct i2c_client *client = OV4686->client; in OV4686_set_ctrl()
1260 max = OV4686->cur_mode->height + ctrl->val - 4; in OV4686_set_ctrl()
1261 __v4l2_ctrl_modify_range(OV4686->exposure, in OV4686_set_ctrl()
1262 OV4686->exposure->minimum, max, in OV4686_set_ctrl()
1263 OV4686->exposure->step, in OV4686_set_ctrl()
1264 OV4686->exposure->default_value); in OV4686_set_ctrl()
1274 ret = OV4686_write_reg(OV4686->client, OV4686_REG_EXPOSURE, in OV4686_set_ctrl()
1278 ret = OV4686_write_reg(OV4686->client, OV4686_REG_GAIN_H, in OV4686_set_ctrl()
1281 ret |= OV4686_write_reg(OV4686->client, OV4686_REG_GAIN_L, in OV4686_set_ctrl()
1286 ret = OV4686_write_reg(OV4686->client, OV4686_REG_VTS, in OV4686_set_ctrl()
1288 ctrl->val + OV4686->cur_mode->height); in OV4686_set_ctrl()
1291 ret = OV4686_enable_test_pattern(OV4686, ctrl->val); in OV4686_set_ctrl()
1294 ret = OV4686_read_reg(OV4686->client, OV4686_HFLIP_REG, in OV4686_set_ctrl()
1301 ret = OV4686_write_reg(OV4686->client, OV4686_HFLIP_REG, in OV4686_set_ctrl()
1306 ret = OV4686_read_reg(OV4686->client, OV4686_VFLIP_REG, in OV4686_set_ctrl()
1313 ret = OV4686_write_reg(OV4686->client, OV4686_VFLIP_REG, in OV4686_set_ctrl()
1332 static int OV4686_initialize_controls(struct OV4686 *OV4686) in OV4686_initialize_controls() argument
1341 handler = &OV4686->ctrl_handler; in OV4686_initialize_controls()
1342 mode = OV4686->cur_mode; in OV4686_initialize_controls()
1346 handler->lock = &OV4686->mutex; in OV4686_initialize_controls()
1357 OV4686->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in OV4686_initialize_controls()
1359 if (OV4686->hblank) in OV4686_initialize_controls()
1360 OV4686->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in OV4686_initialize_controls()
1363 OV4686->vblank = v4l2_ctrl_new_std(handler, &OV4686_ctrl_ops, in OV4686_initialize_controls()
1369 OV4686->exposure = v4l2_ctrl_new_std(handler, &OV4686_ctrl_ops, in OV4686_initialize_controls()
1374 OV4686->anal_gain = v4l2_ctrl_new_std(handler, &OV4686_ctrl_ops, in OV4686_initialize_controls()
1379 OV4686->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in OV4686_initialize_controls()
1391 dev_err(&OV4686->client->dev, in OV4686_initialize_controls()
1396 OV4686->subdev.ctrl_handler = handler; in OV4686_initialize_controls()
1397 OV4686->has_init_exp = false; in OV4686_initialize_controls()
1407 static int OV4686_check_sensor_id(struct OV4686 *OV4686, in OV4686_check_sensor_id() argument
1410 struct device *dev = &OV4686->client->dev; in OV4686_check_sensor_id()
1426 static int OV4686_configure_regulators(struct OV4686 *OV4686) in OV4686_configure_regulators() argument
1431 OV4686->supplies[i].supply = OV4686_supply_names[i]; in OV4686_configure_regulators()
1433 return devm_regulator_bulk_get(&OV4686->client->dev, in OV4686_configure_regulators()
1435 OV4686->supplies); in OV4686_configure_regulators()
1443 struct OV4686 *OV4686; in OV4686_probe() local
1454 OV4686 = devm_kzalloc(dev, sizeof(*OV4686), GFP_KERNEL); in OV4686_probe()
1455 if (!OV4686) in OV4686_probe()
1460 &OV4686->module_index); in OV4686_probe()
1462 &OV4686->module_facing); in OV4686_probe()
1464 &OV4686->module_name); in OV4686_probe()
1466 &OV4686->len_name); in OV4686_probe()
1472 OV4686->client = client; in OV4686_probe()
1475 OV4686->cur_mode = &supported_modes[i]; in OV4686_probe()
1480 OV4686->cur_mode = &supported_modes[0]; in OV4686_probe()
1482 OV4686->xvclk = devm_clk_get(dev, "xvclk"); in OV4686_probe()
1483 if (IS_ERR(OV4686->xvclk)) { in OV4686_probe()
1488 OV4686->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in OV4686_probe()
1489 if (IS_ERR(OV4686->reset_gpio)) in OV4686_probe()
1492 OV4686->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in OV4686_probe()
1493 if (IS_ERR(OV4686->pwdn_gpio)) in OV4686_probe()
1496 OV4686->pinctrl = devm_pinctrl_get(dev); in OV4686_probe()
1497 if (!IS_ERR(OV4686->pinctrl)) { in OV4686_probe()
1498 OV4686->pins_default = in OV4686_probe()
1499 pinctrl_lookup_state(OV4686->pinctrl, in OV4686_probe()
1501 if (IS_ERR(OV4686->pins_default)) in OV4686_probe()
1504 OV4686->pins_sleep = in OV4686_probe()
1505 pinctrl_lookup_state(OV4686->pinctrl, in OV4686_probe()
1507 if (IS_ERR(OV4686->pins_sleep)) in OV4686_probe()
1513 ret = OV4686_configure_regulators(OV4686); in OV4686_probe()
1519 mutex_init(&OV4686->mutex); in OV4686_probe()
1521 sd = &OV4686->subdev; in OV4686_probe()
1523 ret = OV4686_initialize_controls(OV4686); in OV4686_probe()
1527 ret = __OV4686_power_on(OV4686); in OV4686_probe()
1531 ret = OV4686_check_sensor_id(OV4686, client); in OV4686_probe()
1541 OV4686->pad.flags = MEDIA_PAD_FL_SOURCE; in OV4686_probe()
1543 ret = media_entity_pads_init(&sd->entity, 1, &OV4686->pad); in OV4686_probe()
1549 if (strcmp(OV4686->module_facing, "back") == 0) in OV4686_probe()
1555 OV4686->module_index, facing, in OV4686_probe()
1574 __OV4686_power_off(OV4686); in OV4686_probe()
1576 v4l2_ctrl_handler_free(&OV4686->ctrl_handler); in OV4686_probe()
1578 mutex_destroy(&OV4686->mutex); in OV4686_probe()
1586 struct OV4686 *OV4686 = to_OV4686(sd); in OV4686_remove() local
1592 v4l2_ctrl_handler_free(&OV4686->ctrl_handler); in OV4686_remove()
1593 mutex_destroy(&OV4686->mutex); in OV4686_remove()
1597 __OV4686_power_off(OV4686); in OV4686_remove()