Lines Matching +full:gpio +full:- +full:ctrl1
1 // SPDX-License-Identifier: GPL-2.0-only
13 #include <linux/gpio/consumer.h>
20 #include <media/v4l2-ctrls.h>
21 #include <media/v4l2-event.h>
22 #include <media/v4l2-fwnode.h>
23 #include <media/v4l2-image-sizes.h>
24 #include <media/v4l2-subdev.h>
181 u8 ctrl1; member
719 static const struct pll_ctrl_reg ctrl1[] = { variable
833 msg.addr = client->addr; in ov2659_write()
834 msg.flags = client->flags; in ov2659_write()
838 ret = i2c_transfer(client->adapter, &msg, 1); in ov2659_write()
842 dev_dbg(&client->dev, in ov2659_write()
858 msg[0].addr = client->addr; in ov2659_read()
859 msg[0].flags = client->flags; in ov2659_read()
863 msg[1].addr = client->addr; in ov2659_read()
864 msg[1].flags = client->flags | I2C_M_RD; in ov2659_read()
868 ret = i2c_transfer(client->adapter, msg, 2); in ov2659_read()
874 dev_dbg(&client->dev, in ov2659_read()
893 const struct ov2659_platform_data *pdata = ov2659->pdata; in ov2659_pll_calc_params()
895 struct i2c_client *client = ov2659->client; in ov2659_pll_calc_params()
896 unsigned int desired = pdata->link_frequency; in ov2659_pll_calc_params()
898 u32 bestdelta = -1; in ov2659_pll_calc_params()
902 for (i = 0; ctrl1[i].div != 0; i++) { in ov2659_pll_calc_params()
903 postdiv = ctrl1[i].div; in ov2659_pll_calc_params()
907 actual = ov2659->xvclk_frequency; in ov2659_pll_calc_params()
911 delta = actual - desired; in ov2659_pll_calc_params()
914 if ((delta < bestdelta) || (bestdelta == -1)) { in ov2659_pll_calc_params()
916 ctrl1_reg = ctrl1[i].reg; in ov2659_pll_calc_params()
924 ov2659->pll.ctrl1 = ctrl1_reg; in ov2659_pll_calc_params()
925 ov2659->pll.ctrl2 = ctrl2_reg; in ov2659_pll_calc_params()
926 ov2659->pll.ctrl3 = ctrl3_reg; in ov2659_pll_calc_params()
928 dev_dbg(&client->dev, in ov2659_pll_calc_params()
935 struct i2c_client *client = ov2659->client; in ov2659_set_pixel_clock()
937 {REG_SC_PLL_CTRL1, ov2659->pll.ctrl1}, in ov2659_set_pixel_clock()
938 {REG_SC_PLL_CTRL2, ov2659->pll.ctrl2}, in ov2659_set_pixel_clock()
939 {REG_SC_PLL_CTRL3, ov2659->pll.ctrl3}, in ov2659_set_pixel_clock()
943 dev_dbg(&client->dev, "%s\n", __func__); in ov2659_set_pixel_clock()
950 format->width = ov2659_framesizes[2].width; in ov2659_get_default_format()
951 format->height = ov2659_framesizes[2].height; in ov2659_get_default_format()
952 format->colorspace = V4L2_COLORSPACE_SRGB; in ov2659_get_default_format()
953 format->code = ov2659_formats[0].code; in ov2659_get_default_format()
954 format->field = V4L2_FIELD_NONE; in ov2659_get_default_format()
959 struct i2c_client *client = ov2659->client; in ov2659_set_streaming()
964 dev_dbg(&client->dev, "%s: on: %d\n", __func__, on); in ov2659_set_streaming()
968 dev_err(&client->dev, "ov2659 soft standby failed\n"); in ov2659_set_streaming()
988 dev_dbg(&client->dev, "%s:\n", __func__); in ov2659_enum_mbus_code()
990 if (code->index >= ARRAY_SIZE(ov2659_formats)) in ov2659_enum_mbus_code()
991 return -EINVAL; in ov2659_enum_mbus_code()
993 code->code = ov2659_formats[code->index].code; in ov2659_enum_mbus_code()
1005 dev_dbg(&client->dev, "%s:\n", __func__); in ov2659_enum_frame_sizes()
1007 if (fse->index >= ARRAY_SIZE(ov2659_framesizes)) in ov2659_enum_frame_sizes()
1008 return -EINVAL; in ov2659_enum_frame_sizes()
1010 while (--i) in ov2659_enum_frame_sizes()
1011 if (fse->code == ov2659_formats[i].code) in ov2659_enum_frame_sizes()
1014 fse->code = ov2659_formats[i].code; in ov2659_enum_frame_sizes()
1016 fse->min_width = ov2659_framesizes[fse->index].width; in ov2659_enum_frame_sizes()
1017 fse->max_width = fse->min_width; in ov2659_enum_frame_sizes()
1018 fse->max_height = ov2659_framesizes[fse->index].height; in ov2659_enum_frame_sizes()
1019 fse->min_height = fse->max_height; in ov2659_enum_frame_sizes()
1031 dev_dbg(&client->dev, "ov2659_get_fmt\n"); in ov2659_get_fmt()
1033 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in ov2659_get_fmt()
1037 mutex_lock(&ov2659->lock); in ov2659_get_fmt()
1038 fmt->format = *mf; in ov2659_get_fmt()
1039 mutex_unlock(&ov2659->lock); in ov2659_get_fmt()
1043 mutex_lock(&ov2659->lock); in ov2659_get_fmt()
1044 fmt->format = ov2659->format; in ov2659_get_fmt()
1045 mutex_unlock(&ov2659->lock); in ov2659_get_fmt()
1047 dev_dbg(&client->dev, "ov2659_get_fmt: %x %dx%d\n", in ov2659_get_fmt()
1048 ov2659->format.code, ov2659->format.width, in ov2659_get_fmt()
1049 ov2659->format.height); in ov2659_get_fmt()
1062 while (i--) { in __ov2659_try_frame_size()
1063 int err = abs(fsize->width - mf->width) in __ov2659_try_frame_size()
1064 + abs(fsize->height - mf->height); in __ov2659_try_frame_size()
1065 if ((err < min_err) && (fsize->regs[0].addr)) { in __ov2659_try_frame_size()
1075 mf->width = match->width; in __ov2659_try_frame_size()
1076 mf->height = match->height; in __ov2659_try_frame_size()
1088 struct v4l2_mbus_framefmt *mf = &fmt->format; in ov2659_set_fmt()
1093 dev_dbg(&client->dev, "ov2659_set_fmt\n"); in ov2659_set_fmt()
1097 while (--index >= 0) in ov2659_set_fmt()
1098 if (ov2659_formats[index].code == mf->code) in ov2659_set_fmt()
1103 mf->code = ov2659_formats[index].code; in ov2659_set_fmt()
1106 mf->colorspace = V4L2_COLORSPACE_SRGB; in ov2659_set_fmt()
1107 mf->field = V4L2_FIELD_NONE; in ov2659_set_fmt()
1109 mutex_lock(&ov2659->lock); in ov2659_set_fmt()
1111 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in ov2659_set_fmt()
1112 mf = v4l2_subdev_state_get_format(sd_state, fmt->pad); in ov2659_set_fmt()
1113 *mf = fmt->format; in ov2659_set_fmt()
1117 if (ov2659->streaming) { in ov2659_set_fmt()
1118 mutex_unlock(&ov2659->lock); in ov2659_set_fmt()
1119 return -EBUSY; in ov2659_set_fmt()
1122 ov2659->frame_size = size; in ov2659_set_fmt()
1123 ov2659->format = fmt->format; in ov2659_set_fmt()
1124 ov2659->format_ctrl_regs = in ov2659_set_fmt()
1127 if (ov2659->format.code != MEDIA_BUS_FMT_SBGGR8_1X8) in ov2659_set_fmt()
1128 val = ov2659->pdata->link_frequency / 2; in ov2659_set_fmt()
1130 val = ov2659->pdata->link_frequency; in ov2659_set_fmt()
1132 ret = v4l2_ctrl_s_ctrl_int64(ov2659->link_frequency, val); in ov2659_set_fmt()
1134 dev_warn(&client->dev, in ov2659_set_fmt()
1139 mutex_unlock(&ov2659->lock); in ov2659_set_fmt()
1145 struct i2c_client *client = ov2659->client; in ov2659_set_frame_size()
1147 dev_dbg(&client->dev, "%s\n", __func__); in ov2659_set_frame_size()
1149 return ov2659_write_array(ov2659->client, ov2659->frame_size->regs); in ov2659_set_frame_size()
1154 struct i2c_client *client = ov2659->client; in ov2659_set_format()
1156 dev_dbg(&client->dev, "%s\n", __func__); in ov2659_set_format()
1158 return ov2659_write_array(ov2659->client, ov2659->format_ctrl_regs); in ov2659_set_format()
1167 dev_dbg(&client->dev, "%s: on: %d\n", __func__, on); in ov2659_s_stream()
1169 mutex_lock(&ov2659->lock); in ov2659_s_stream()
1173 if (ov2659->streaming == on) in ov2659_s_stream()
1179 ov2659->streaming = on; in ov2659_s_stream()
1180 pm_runtime_put(&client->dev); in ov2659_s_stream()
1184 ret = pm_runtime_resume_and_get(&client->dev); in ov2659_s_stream()
1197 ov2659->streaming = on; in ov2659_s_stream()
1201 mutex_unlock(&ov2659->lock); in ov2659_s_stream()
1207 struct i2c_client *client = v4l2_get_subdevdata(&ov2659->sd); in ov2659_set_test_pattern()
1231 container_of(ctrl->handler, struct ov2659, ctrls); in ov2659_s_ctrl()
1232 struct i2c_client *client = ov2659->client; in ov2659_s_ctrl()
1235 if (!pm_runtime_get_if_in_use(&client->dev)) in ov2659_s_ctrl()
1238 switch (ctrl->id) { in ov2659_s_ctrl()
1240 return ov2659_set_test_pattern(ov2659, ctrl->val); in ov2659_s_ctrl()
1243 pm_runtime_put(&client->dev); in ov2659_s_ctrl()
1262 dev_dbg(&client->dev, "%s:\n", __func__); in ov2659_power_off()
1264 gpiod_set_value(ov2659->pwdn_gpio, 1); in ov2659_power_off()
1266 clk_disable_unprepare(ov2659->clk); in ov2659_power_off()
1278 dev_dbg(&client->dev, "%s:\n", __func__); in ov2659_power_on()
1280 ret = clk_prepare_enable(ov2659->clk); in ov2659_power_on()
1282 dev_err(&client->dev, "%s: failed to enable clock\n", in ov2659_power_on()
1287 gpiod_set_value(ov2659->pwdn_gpio, 0); in ov2659_power_on()
1289 if (ov2659->resetb_gpio) { in ov2659_power_on()
1290 gpiod_set_value(ov2659->resetb_gpio, 1); in ov2659_power_on()
1292 gpiod_set_value(ov2659->resetb_gpio, 0); in ov2659_power_on()
1299 /* -----------------------------------------------------------------------------
1307 v4l2_subdev_state_get_format(fh->state, 0); in ov2659_open()
1309 dev_dbg(&client->dev, "%s:\n", __func__); in ov2659_open()
1350 dev_dbg(&client->dev, "%s:\n", __func__); in ov2659_detect()
1354 dev_err(&client->dev, "Sensor soft reset failed\n"); in ov2659_detect()
1355 return -ENODEV; in ov2659_detect()
1369 dev_err(&client->dev, in ov2659_detect()
1371 ret = -ENODEV; in ov2659_detect()
1373 dev_info(&client->dev, "Found OV%04X sensor\n", id); in ov2659_detect()
1388 if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) in ov2659_get_pdata()
1389 return client->dev.platform_data; in ov2659_get_pdata()
1391 endpoint = of_graph_get_endpoint_by_regs(client->dev.of_node, 0, -1); in ov2659_get_pdata()
1402 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); in ov2659_get_pdata()
1407 dev_err(&client->dev, in ov2659_get_pdata()
1408 "link-frequencies property not found or too many\n"); in ov2659_get_pdata()
1413 pdata->link_frequency = bus_cfg.link_frequencies[0]; in ov2659_get_pdata()
1429 dev_err(&client->dev, "platform data not specified\n"); in ov2659_probe()
1430 return -EINVAL; in ov2659_probe()
1433 ov2659 = devm_kzalloc(&client->dev, sizeof(*ov2659), GFP_KERNEL); in ov2659_probe()
1435 return -ENOMEM; in ov2659_probe()
1437 ov2659->pdata = pdata; in ov2659_probe()
1438 ov2659->client = client; in ov2659_probe()
1440 ov2659->clk = devm_clk_get(&client->dev, "xvclk"); in ov2659_probe()
1441 if (IS_ERR(ov2659->clk)) in ov2659_probe()
1442 return PTR_ERR(ov2659->clk); in ov2659_probe()
1444 ov2659->xvclk_frequency = clk_get_rate(ov2659->clk); in ov2659_probe()
1445 if (ov2659->xvclk_frequency < 6000000 || in ov2659_probe()
1446 ov2659->xvclk_frequency > 27000000) in ov2659_probe()
1447 return -EINVAL; in ov2659_probe()
1449 /* Optional gpio don't fail if not present */ in ov2659_probe()
1450 ov2659->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", in ov2659_probe()
1452 if (IS_ERR(ov2659->pwdn_gpio)) in ov2659_probe()
1453 return PTR_ERR(ov2659->pwdn_gpio); in ov2659_probe()
1455 /* Optional gpio don't fail if not present */ in ov2659_probe()
1456 ov2659->resetb_gpio = devm_gpiod_get_optional(&client->dev, "reset", in ov2659_probe()
1458 if (IS_ERR(ov2659->resetb_gpio)) in ov2659_probe()
1459 return PTR_ERR(ov2659->resetb_gpio); in ov2659_probe()
1461 v4l2_ctrl_handler_init(&ov2659->ctrls, 2); in ov2659_probe()
1462 ov2659->link_frequency = in ov2659_probe()
1463 v4l2_ctrl_new_std(&ov2659->ctrls, &ov2659_ctrl_ops, in ov2659_probe()
1465 pdata->link_frequency / 2, in ov2659_probe()
1466 pdata->link_frequency, 1, in ov2659_probe()
1467 pdata->link_frequency); in ov2659_probe()
1468 v4l2_ctrl_new_std_menu_items(&ov2659->ctrls, &ov2659_ctrl_ops, in ov2659_probe()
1470 ARRAY_SIZE(ov2659_test_pattern_menu) - 1, in ov2659_probe()
1472 ov2659->sd.ctrl_handler = &ov2659->ctrls; in ov2659_probe()
1474 if (ov2659->ctrls.error) { in ov2659_probe()
1475 dev_err(&client->dev, "%s: control initialization error %d\n", in ov2659_probe()
1476 __func__, ov2659->ctrls.error); in ov2659_probe()
1477 return ov2659->ctrls.error; in ov2659_probe()
1480 sd = &ov2659->sd; in ov2659_probe()
1481 client->flags |= I2C_CLIENT_SCCB; in ov2659_probe()
1484 sd->internal_ops = &ov2659_subdev_internal_ops; in ov2659_probe()
1485 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov2659_probe()
1488 ov2659->pad.flags = MEDIA_PAD_FL_SOURCE; in ov2659_probe()
1489 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov2659_probe()
1490 ret = media_entity_pads_init(&sd->entity, 1, &ov2659->pad); in ov2659_probe()
1492 v4l2_ctrl_handler_free(&ov2659->ctrls); in ov2659_probe()
1496 mutex_init(&ov2659->lock); in ov2659_probe()
1498 ov2659_get_default_format(&ov2659->format); in ov2659_probe()
1499 ov2659->frame_size = &ov2659_framesizes[2]; in ov2659_probe()
1500 ov2659->format_ctrl_regs = ov2659_formats[0].format_ctrl_regs; in ov2659_probe()
1502 ret = ov2659_power_on(&client->dev); in ov2659_probe()
1513 ret = v4l2_async_register_subdev(&ov2659->sd); in ov2659_probe()
1517 dev_info(&client->dev, "%s sensor driver registered !!\n", sd->name); in ov2659_probe()
1519 pm_runtime_set_active(&client->dev); in ov2659_probe()
1520 pm_runtime_enable(&client->dev); in ov2659_probe()
1521 pm_runtime_idle(&client->dev); in ov2659_probe()
1526 v4l2_ctrl_handler_free(&ov2659->ctrls); in ov2659_probe()
1527 ov2659_power_off(&client->dev); in ov2659_probe()
1528 media_entity_cleanup(&sd->entity); in ov2659_probe()
1529 mutex_destroy(&ov2659->lock); in ov2659_probe()
1538 v4l2_ctrl_handler_free(&ov2659->ctrls); in ov2659_remove()
1540 media_entity_cleanup(&sd->entity); in ov2659_remove()
1541 mutex_destroy(&ov2659->lock); in ov2659_remove()
1543 pm_runtime_disable(&client->dev); in ov2659_remove()
1544 if (!pm_runtime_status_suspended(&client->dev)) in ov2659_remove()
1545 ov2659_power_off(&client->dev); in ov2659_remove()
1546 pm_runtime_set_suspended(&client->dev); in ov2659_remove()