Lines Matching refs:gc3003
115 struct gc3003 { struct
158 #define to_gc3003(sd) container_of(sd, struct gc3003, subdev) argument
878 gc3003_find_best_fit(struct gc3003 *gc3003, struct v4l2_subdev_format *fmt) in gc3003_find_best_fit() argument
886 for (i = 0; i < gc3003->cfg_num; i++) { in gc3003_find_best_fit()
901 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_set_fmt() local
905 mutex_lock(&gc3003->mutex); in gc3003_set_fmt()
907 mode = gc3003_find_best_fit(gc3003, fmt); in gc3003_set_fmt()
916 mutex_unlock(&gc3003->mutex); in gc3003_set_fmt()
920 gc3003->cur_mode = mode; in gc3003_set_fmt()
922 __v4l2_ctrl_modify_range(gc3003->hblank, h_blank, in gc3003_set_fmt()
925 __v4l2_ctrl_modify_range(gc3003->vblank, vblank_def, in gc3003_set_fmt()
929 gc3003->cur_link_freq = 0; in gc3003_set_fmt()
930 gc3003->cur_pixel_rate = GC3003_PIXEL_RATE_LINEAR; in gc3003_set_fmt()
932 __v4l2_ctrl_s_ctrl_int64(gc3003->pixel_rate, in gc3003_set_fmt()
933 gc3003->cur_pixel_rate); in gc3003_set_fmt()
934 __v4l2_ctrl_s_ctrl(gc3003->link_freq, in gc3003_set_fmt()
935 gc3003->cur_link_freq); in gc3003_set_fmt()
936 gc3003->cur_vts = mode->vts_def; in gc3003_set_fmt()
939 mutex_unlock(&gc3003->mutex); in gc3003_set_fmt()
948 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_get_fmt() local
949 const struct gc3003_mode *mode = gc3003->cur_mode; in gc3003_get_fmt()
951 mutex_lock(&gc3003->mutex); in gc3003_get_fmt()
956 mutex_unlock(&gc3003->mutex); in gc3003_get_fmt()
965 mutex_unlock(&gc3003->mutex); in gc3003_get_fmt()
974 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_enum_mbus_code() local
978 code->code = gc3003->cur_mode->bus_fmt; in gc3003_enum_mbus_code()
987 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_enum_frame_sizes() local
989 if (fse->index >= gc3003->cfg_num) in gc3003_enum_frame_sizes()
1003 static int gc3003_enable_test_pattern(struct gc3003 *gc3003, u32 pattern) in gc3003_enable_test_pattern() argument
1012 return gc3003_write_reg(gc3003->client, GC3003_REG_TEST_PATTERN, in gc3003_enable_test_pattern()
1015 static int gc3003_set_gain_reg(struct gc3003 *gc3003, u32 gain) in gc3003_set_gain_reg() argument
1033 gc3003_write_reg(gc3003->client, 0x0d1, in gc3003_set_gain_reg()
1035 gc3003_write_reg(gc3003->client, 0x0d0, in gc3003_set_gain_reg()
1037 gc3003_write_reg(gc3003->client, 0x080, in gc3003_set_gain_reg()
1039 gc3003_write_reg(gc3003->client, 0x155, in gc3003_set_gain_reg()
1041 gc3003_write_reg(gc3003->client, 0x0b8, in gc3003_set_gain_reg()
1043 gc3003_write_reg(gc3003->client, 0x0b9, in gc3003_set_gain_reg()
1045 gc3003_write_reg(gc3003->client, 0x0b1, in gc3003_set_gain_reg()
1047 gc3003_write_reg(gc3003->client, 0x0b2, in gc3003_set_gain_reg()
1055 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_g_frame_interval() local
1056 const struct gc3003_mode *mode = gc3003->cur_mode; in gc3003_g_frame_interval()
1066 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_g_mbus_config() local
1067 const struct gc3003_mode *mode = gc3003->cur_mode; in gc3003_g_mbus_config()
1081 static void gc3003_get_module_inf(struct gc3003 *gc3003, in gc3003_get_module_inf() argument
1086 strscpy(inf->base.module, gc3003->module_name, in gc3003_get_module_inf()
1088 strscpy(inf->base.lens, gc3003->len_name, sizeof(inf->base.lens)); in gc3003_get_module_inf()
1091 static int gc3003_get_channel_info(struct gc3003 *gc3003, struct rkmodule_channel_info *ch_info) in gc3003_get_channel_info() argument
1095 ch_info->vc = gc3003->cur_mode->vc[ch_info->index]; in gc3003_get_channel_info()
1096 ch_info->width = gc3003->cur_mode->width; in gc3003_get_channel_info()
1097 ch_info->height = gc3003->cur_mode->height; in gc3003_get_channel_info()
1098 ch_info->bus_fmt = gc3003->cur_mode->bus_fmt; in gc3003_get_channel_info()
1104 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_ioctl() local
1113 gc3003_get_module_inf(gc3003, (struct rkmodule_inf *)arg); in gc3003_ioctl()
1118 hdr->hdr_mode = gc3003->cur_mode->hdr_mode; in gc3003_ioctl()
1122 w = gc3003->cur_mode->width; in gc3003_ioctl()
1123 h = gc3003->cur_mode->height; in gc3003_ioctl()
1124 for (i = 0; i < gc3003->cfg_num; i++) { in gc3003_ioctl()
1128 gc3003->cur_mode = &supported_modes[i]; in gc3003_ioctl()
1132 if (i == gc3003->cfg_num) { in gc3003_ioctl()
1133 dev_err(&gc3003->client->dev, in gc3003_ioctl()
1138 w = gc3003->cur_mode->hts_def - in gc3003_ioctl()
1139 gc3003->cur_mode->width; in gc3003_ioctl()
1140 h = gc3003->cur_mode->vts_def - in gc3003_ioctl()
1141 gc3003->cur_mode->height; in gc3003_ioctl()
1142 __v4l2_ctrl_modify_range(gc3003->hblank, w, w, 1, w); in gc3003_ioctl()
1143 __v4l2_ctrl_modify_range(gc3003->vblank, h, in gc3003_ioctl()
1145 gc3003->cur_mode->height, in gc3003_ioctl()
1147 gc3003->cur_link_freq = 0; in gc3003_ioctl()
1148 gc3003->cur_pixel_rate = GC3003_PIXEL_RATE_LINEAR; in gc3003_ioctl()
1150 __v4l2_ctrl_s_ctrl_int64(gc3003->pixel_rate, in gc3003_ioctl()
1151 gc3003->cur_pixel_rate); in gc3003_ioctl()
1152 __v4l2_ctrl_s_ctrl(gc3003->link_freq, in gc3003_ioctl()
1153 gc3003->cur_link_freq); in gc3003_ioctl()
1154 gc3003->cur_vts = gc3003->cur_mode->vts_def; in gc3003_ioctl()
1164 ret = gc3003_write_reg(gc3003->client, GC3003_REG_CTRL_MODE, in gc3003_ioctl()
1167 ret = gc3003_write_reg(gc3003->client, GC3003_REG_CTRL_MODE, in gc3003_ioctl()
1172 ret = gc3003_get_channel_info(gc3003, ch_info); in gc3003_ioctl()
1299 static int __gc3003_start_stream(struct gc3003 *gc3003) in __gc3003_start_stream() argument
1303 if (!gc3003->is_thunderboot) { in __gc3003_start_stream()
1304 ret = gc3003_write_array(gc3003->client, gc3003->cur_mode->reg_list); in __gc3003_start_stream()
1309 ret = __v4l2_ctrl_handler_setup(&gc3003->ctrl_handler); in __gc3003_start_stream()
1312 if (gc3003->has_init_exp && gc3003->cur_mode->hdr_mode != NO_HDR) { in __gc3003_start_stream()
1313 ret = gc3003_ioctl(&gc3003->subdev, PREISP_CMD_SET_HDRAE_EXP, in __gc3003_start_stream()
1314 &gc3003->init_hdrae_exp); in __gc3003_start_stream()
1316 dev_err(&gc3003->client->dev, in __gc3003_start_stream()
1323 ret = gc3003_write_array(gc3003->client, gc3003->cur_mode->stream_on_reg_list); in __gc3003_start_stream()
1328 static int __gc3003_stop_stream(struct gc3003 *gc3003) in __gc3003_stop_stream() argument
1332 gc3003->has_init_exp = false; in __gc3003_stop_stream()
1333 if (gc3003->is_thunderboot) { in __gc3003_stop_stream()
1334 gc3003->is_first_streamoff = true; in __gc3003_stop_stream()
1335 pm_runtime_put(&gc3003->client->dev); in __gc3003_stop_stream()
1337 ret = gc3003_write_array(gc3003->client, gc3003->cur_mode->stand_by_reg_list); in __gc3003_stop_stream()
1342 static int __gc3003_power_on(struct gc3003 *gc3003);
1345 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_s_stream() local
1346 struct i2c_client *client = gc3003->client; in gc3003_s_stream()
1349 mutex_lock(&gc3003->mutex); in gc3003_s_stream()
1351 if (on == gc3003->streaming) in gc3003_s_stream()
1355 if (gc3003->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) { in gc3003_s_stream()
1356 gc3003->is_thunderboot = false; in gc3003_s_stream()
1357 __gc3003_power_on(gc3003); in gc3003_s_stream()
1365 ret = __gc3003_start_stream(gc3003); in gc3003_s_stream()
1372 __gc3003_stop_stream(gc3003); in gc3003_s_stream()
1376 gc3003->streaming = on; in gc3003_s_stream()
1379 mutex_unlock(&gc3003->mutex); in gc3003_s_stream()
1386 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_s_power() local
1387 struct i2c_client *client = gc3003->client; in gc3003_s_power()
1390 mutex_lock(&gc3003->mutex); in gc3003_s_power()
1393 if (gc3003->power_on == !!on) in gc3003_s_power()
1403 if (!gc3003->is_thunderboot) { in gc3003_s_power()
1404 ret = gc3003_write_array(gc3003->client, gc3003_global_regs); in gc3003_s_power()
1412 gc3003->power_on = true; in gc3003_s_power()
1415 gc3003->power_on = false; in gc3003_s_power()
1419 mutex_unlock(&gc3003->mutex); in gc3003_s_power()
1430 static int __gc3003_power_on(struct gc3003 *gc3003) in __gc3003_power_on() argument
1434 struct device *dev = &gc3003->client->dev; in __gc3003_power_on()
1436 if (!IS_ERR_OR_NULL(gc3003->pins_default)) { in __gc3003_power_on()
1437 ret = pinctrl_select_state(gc3003->pinctrl, in __gc3003_power_on()
1438 gc3003->pins_default); in __gc3003_power_on()
1442 ret = clk_set_rate(gc3003->xvclk, GC3003_XVCLK_FREQ); in __gc3003_power_on()
1445 if (clk_get_rate(gc3003->xvclk) != GC3003_XVCLK_FREQ) in __gc3003_power_on()
1447 ret = clk_prepare_enable(gc3003->xvclk); in __gc3003_power_on()
1453 if (gc3003->is_thunderboot) in __gc3003_power_on()
1456 if (!IS_ERR(gc3003->reset_gpio)) in __gc3003_power_on()
1457 gpiod_set_value_cansleep(gc3003->reset_gpio, 0); in __gc3003_power_on()
1459 if (!IS_ERR(gc3003->pwdn_gpio)) in __gc3003_power_on()
1460 gpiod_set_value_cansleep(gc3003->pwdn_gpio, 0); in __gc3003_power_on()
1463 ret = regulator_bulk_enable(GC3003_NUM_SUPPLIES, gc3003->supplies); in __gc3003_power_on()
1470 if (!IS_ERR(gc3003->pwren_gpio)) in __gc3003_power_on()
1471 gpiod_set_value_cansleep(gc3003->pwren_gpio, 1); in __gc3003_power_on()
1474 if (!IS_ERR(gc3003->pwdn_gpio)) in __gc3003_power_on()
1475 gpiod_set_value_cansleep(gc3003->pwdn_gpio, 1); in __gc3003_power_on()
1477 if (!IS_ERR(gc3003->reset_gpio)) in __gc3003_power_on()
1478 gpiod_set_value_cansleep(gc3003->reset_gpio, 1); in __gc3003_power_on()
1487 clk_disable_unprepare(gc3003->xvclk); in __gc3003_power_on()
1492 static void __gc3003_power_off(struct gc3003 *gc3003) in __gc3003_power_off() argument
1495 struct device *dev = &gc3003->client->dev; in __gc3003_power_off()
1497 clk_disable_unprepare(gc3003->xvclk); in __gc3003_power_off()
1498 if (gc3003->is_thunderboot) { in __gc3003_power_off()
1499 if (gc3003->is_first_streamoff) { in __gc3003_power_off()
1500 gc3003->is_thunderboot = false; in __gc3003_power_off()
1501 gc3003->is_first_streamoff = false; in __gc3003_power_off()
1507 if (!IS_ERR(gc3003->pwdn_gpio)) in __gc3003_power_off()
1508 gpiod_set_value_cansleep(gc3003->pwdn_gpio, 0); in __gc3003_power_off()
1509 clk_disable_unprepare(gc3003->xvclk); in __gc3003_power_off()
1510 if (!IS_ERR(gc3003->reset_gpio)) in __gc3003_power_off()
1511 gpiod_set_value_cansleep(gc3003->reset_gpio, 0); in __gc3003_power_off()
1512 if (!IS_ERR_OR_NULL(gc3003->pins_sleep)) { in __gc3003_power_off()
1513 ret = pinctrl_select_state(gc3003->pinctrl, in __gc3003_power_off()
1514 gc3003->pins_sleep); in __gc3003_power_off()
1518 regulator_bulk_disable(GC3003_NUM_SUPPLIES, gc3003->supplies); in __gc3003_power_off()
1525 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_runtime_resume() local
1527 return __gc3003_power_on(gc3003); in gc3003_runtime_resume()
1534 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_runtime_suspend() local
1536 __gc3003_power_off(gc3003); in gc3003_runtime_suspend()
1544 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_open() local
1549 mutex_lock(&gc3003->mutex); in gc3003_open()
1556 mutex_unlock(&gc3003->mutex); in gc3003_open()
1567 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_enum_frame_interval() local
1569 if (fie->index >= gc3003->cfg_num) in gc3003_enum_frame_interval()
1652 struct gc3003 *gc3003 = container_of(ctrl->handler, in gc3003_set_ctrl() local
1653 struct gc3003, ctrl_handler); in gc3003_set_ctrl()
1654 struct i2c_client *client = gc3003->client; in gc3003_set_ctrl()
1663 max = gc3003->cur_mode->height + ctrl->val - 4; in gc3003_set_ctrl()
1664 __v4l2_ctrl_modify_range(gc3003->exposure, in gc3003_set_ctrl()
1665 gc3003->exposure->minimum, in gc3003_set_ctrl()
1667 gc3003->exposure->step, in gc3003_set_ctrl()
1668 gc3003->exposure->default_value); in gc3003_set_ctrl()
1678 ret = gc3003_write_reg(gc3003->client, GC3003_REG_EXPOSURE_H, in gc3003_set_ctrl()
1681 ret |= gc3003_write_reg(gc3003->client, GC3003_REG_EXPOSURE_L, in gc3003_set_ctrl()
1686 ret = gc3003_set_gain_reg(gc3003, ctrl->val); in gc3003_set_ctrl()
1689 gc3003->cur_vts = ctrl->val + gc3003->cur_mode->height; in gc3003_set_ctrl()
1690 ret = gc3003_write_reg(gc3003->client, GC3003_REG_VTS_H, in gc3003_set_ctrl()
1692 gc3003->cur_vts >> 8); in gc3003_set_ctrl()
1693 ret |= gc3003_write_reg(gc3003->client, GC3003_REG_VTS_L, in gc3003_set_ctrl()
1695 gc3003->cur_vts & 0xff); in gc3003_set_ctrl()
1698 ret = gc3003_enable_test_pattern(gc3003, ctrl->val); in gc3003_set_ctrl()
1701 ret = gc3003_read_reg(gc3003->client, GC3003_FLIP_MIRROR_REG, in gc3003_set_ctrl()
1707 ret |= gc3003_write_reg(gc3003->client, GC3003_FLIP_MIRROR_REG, in gc3003_set_ctrl()
1711 ret = gc3003_read_reg(gc3003->client, GC3003_FLIP_MIRROR_REG, in gc3003_set_ctrl()
1717 ret |= gc3003_write_reg(gc3003->client, GC3003_FLIP_MIRROR_REG, in gc3003_set_ctrl()
1735 static int gc3003_initialize_controls(struct gc3003 *gc3003) in gc3003_initialize_controls() argument
1743 handler = &gc3003->ctrl_handler; in gc3003_initialize_controls()
1744 mode = gc3003->cur_mode; in gc3003_initialize_controls()
1748 handler->lock = &gc3003->mutex; in gc3003_initialize_controls()
1750 gc3003->link_freq = v4l2_ctrl_new_int_menu(handler, NULL, V4L2_CID_LINK_FREQ, in gc3003_initialize_controls()
1752 gc3003->cur_link_freq = 0; in gc3003_initialize_controls()
1753 gc3003->cur_pixel_rate = GC3003_PIXEL_RATE_LINEAR; in gc3003_initialize_controls()
1755 __v4l2_ctrl_s_ctrl(gc3003->link_freq, in gc3003_initialize_controls()
1756 gc3003->cur_link_freq); in gc3003_initialize_controls()
1758 gc3003->pixel_rate = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, in gc3003_initialize_controls()
1762 gc3003->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in gc3003_initialize_controls()
1764 if (gc3003->hblank) in gc3003_initialize_controls()
1765 gc3003->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in gc3003_initialize_controls()
1768 gc3003->cur_vts = mode->vts_def; in gc3003_initialize_controls()
1769 gc3003->vblank = v4l2_ctrl_new_std(handler, &gc3003_ctrl_ops, in gc3003_initialize_controls()
1775 gc3003->exposure = v4l2_ctrl_new_std(handler, &gc3003_ctrl_ops, in gc3003_initialize_controls()
1782 gc3003->anal_gain = v4l2_ctrl_new_std(handler, &gc3003_ctrl_ops, in gc3003_initialize_controls()
1789 gc3003->test_pattern = in gc3003_initialize_controls()
1796 gc3003->h_flip = v4l2_ctrl_new_std(handler, &gc3003_ctrl_ops, in gc3003_initialize_controls()
1799 gc3003->v_flip = v4l2_ctrl_new_std(handler, &gc3003_ctrl_ops, in gc3003_initialize_controls()
1803 dev_err(&gc3003->client->dev, in gc3003_initialize_controls()
1808 gc3003->subdev.ctrl_handler = handler; in gc3003_initialize_controls()
1809 gc3003->has_init_exp = false; in gc3003_initialize_controls()
1819 static int gc3003_check_sensor_id(struct gc3003 *gc3003, in gc3003_check_sensor_id() argument
1822 struct device *dev = &gc3003->client->dev; in gc3003_check_sensor_id()
1828 if (gc3003->is_thunderboot) { in gc3003_check_sensor_id()
1847 static int gc3003_configure_regulators(struct gc3003 *gc3003) in gc3003_configure_regulators() argument
1852 gc3003->supplies[i].supply = gc3003_supply_names[i]; in gc3003_configure_regulators()
1854 return devm_regulator_bulk_get(&gc3003->client->dev, in gc3003_configure_regulators()
1856 gc3003->supplies); in gc3003_configure_regulators()
1864 struct gc3003 *gc3003; in gc3003_probe() local
1875 gc3003 = devm_kzalloc(dev, sizeof(*gc3003), GFP_KERNEL); in gc3003_probe()
1876 if (!gc3003) in gc3003_probe()
1881 &gc3003->module_index); in gc3003_probe()
1883 &gc3003->module_facing); in gc3003_probe()
1885 &gc3003->module_name); in gc3003_probe()
1887 &gc3003->len_name); in gc3003_probe()
1893 gc3003->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP); in gc3003_probe()
1895 gc3003->client = client; in gc3003_probe()
1896 gc3003->cfg_num = ARRAY_SIZE(supported_modes); in gc3003_probe()
1897 for (i = 0; i < gc3003->cfg_num; i++) { in gc3003_probe()
1899 gc3003->cur_mode = &supported_modes[i]; in gc3003_probe()
1903 if (i == gc3003->cfg_num) in gc3003_probe()
1904 gc3003->cur_mode = &supported_modes[0]; in gc3003_probe()
1906 gc3003->xvclk = devm_clk_get(dev, "xvclk"); in gc3003_probe()
1907 if (IS_ERR(gc3003->xvclk)) { in gc3003_probe()
1912 gc3003->pwren_gpio = devm_gpiod_get(dev, "pwren", GPIOD_ASIS); in gc3003_probe()
1913 if (IS_ERR(gc3003->pwren_gpio)) in gc3003_probe()
1916 gc3003->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); in gc3003_probe()
1917 if (IS_ERR(gc3003->reset_gpio)) in gc3003_probe()
1920 gc3003->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS); in gc3003_probe()
1921 if (IS_ERR(gc3003->pwdn_gpio)) in gc3003_probe()
1924 gc3003->pinctrl = devm_pinctrl_get(dev); in gc3003_probe()
1925 if (!IS_ERR(gc3003->pinctrl)) { in gc3003_probe()
1926 gc3003->pins_default = in gc3003_probe()
1927 pinctrl_lookup_state(gc3003->pinctrl, in gc3003_probe()
1929 if (IS_ERR(gc3003->pins_default)) in gc3003_probe()
1932 gc3003->pins_sleep = in gc3003_probe()
1933 pinctrl_lookup_state(gc3003->pinctrl, in gc3003_probe()
1935 if (IS_ERR(gc3003->pins_sleep)) in gc3003_probe()
1941 ret = gc3003_configure_regulators(gc3003); in gc3003_probe()
1947 mutex_init(&gc3003->mutex); in gc3003_probe()
1949 sd = &gc3003->subdev; in gc3003_probe()
1951 ret = gc3003_initialize_controls(gc3003); in gc3003_probe()
1955 ret = __gc3003_power_on(gc3003); in gc3003_probe()
1961 ret = gc3003_check_sensor_id(gc3003, client); in gc3003_probe()
1971 gc3003->pad.flags = MEDIA_PAD_FL_SOURCE; in gc3003_probe()
1973 ret = media_entity_pads_init(&sd->entity, 1, &gc3003->pad); in gc3003_probe()
1979 if (strcmp(gc3003->module_facing, "back") == 0) in gc3003_probe()
1985 gc3003->module_index, facing, in gc3003_probe()
1995 if (gc3003->is_thunderboot) in gc3003_probe()
2007 __gc3003_power_off(gc3003); in gc3003_probe()
2009 v4l2_ctrl_handler_free(&gc3003->ctrl_handler); in gc3003_probe()
2011 mutex_destroy(&gc3003->mutex); in gc3003_probe()
2019 struct gc3003 *gc3003 = to_gc3003(sd); in gc3003_remove() local
2025 v4l2_ctrl_handler_free(&gc3003->ctrl_handler); in gc3003_remove()
2026 mutex_destroy(&gc3003->mutex); in gc3003_remove()
2030 __gc3003_power_off(gc3003); in gc3003_remove()