ov7251 97 drivers/media/i2c/ov7251.c static inline struct ov7251 *to_ov7251(struct v4l2_subdev *sd) ov7251 99 drivers/media/i2c/ov7251.c return container_of(sd, struct ov7251, sd); ov7251 570 drivers/media/i2c/ov7251.c static int ov7251_regulators_enable(struct ov7251 *ov7251) ov7251 578 drivers/media/i2c/ov7251.c ret = regulator_enable(ov7251->io_regulator); ov7251 580 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "set io voltage failed\n"); ov7251 584 drivers/media/i2c/ov7251.c ret = regulator_enable(ov7251->analog_regulator); ov7251 586 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "set analog voltage failed\n"); ov7251 590 drivers/media/i2c/ov7251.c ret = regulator_enable(ov7251->core_regulator); ov7251 592 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "set core voltage failed\n"); ov7251 599 drivers/media/i2c/ov7251.c regulator_disable(ov7251->analog_regulator); ov7251 602 drivers/media/i2c/ov7251.c regulator_disable(ov7251->io_regulator); ov7251 607 drivers/media/i2c/ov7251.c static void ov7251_regulators_disable(struct ov7251 *ov7251) ov7251 611 drivers/media/i2c/ov7251.c ret = regulator_disable(ov7251->core_regulator); ov7251 613 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "core regulator disable failed\n"); ov7251 615 drivers/media/i2c/ov7251.c ret = regulator_disable(ov7251->analog_regulator); ov7251 617 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "analog regulator disable failed\n"); ov7251 619 drivers/media/i2c/ov7251.c ret = regulator_disable(ov7251->io_regulator); ov7251 621 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "io regulator disable failed\n"); ov7251 624 drivers/media/i2c/ov7251.c static int ov7251_write_reg(struct ov7251 *ov7251, u16 reg, u8 val) ov7251 633 drivers/media/i2c/ov7251.c ret = i2c_master_send(ov7251->i2c_client, regbuf, 3); ov7251 635 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "%s: write reg error %d: reg=%x, val=%x\n", ov7251 643 drivers/media/i2c/ov7251.c static int ov7251_write_seq_regs(struct ov7251 *ov7251, u16 reg, u8 *val, ov7251 658 drivers/media/i2c/ov7251.c ret = i2c_master_send(ov7251->i2c_client, regbuf, nregbuf); ov7251 660 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, ov7251 669 drivers/media/i2c/ov7251.c static int ov7251_read_reg(struct ov7251 *ov7251, u16 reg, u8 *val) ov7251 677 drivers/media/i2c/ov7251.c ret = i2c_master_send(ov7251->i2c_client, regbuf, 2); ov7251 679 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "%s: write reg error %d: reg=%x\n", ov7251 684 drivers/media/i2c/ov7251.c ret = i2c_master_recv(ov7251->i2c_client, val, 1); ov7251 686 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "%s: read reg error %d: reg=%x\n", ov7251 694 drivers/media/i2c/ov7251.c static int ov7251_set_exposure(struct ov7251 *ov7251, s32 exposure) ov7251 704 drivers/media/i2c/ov7251.c return ov7251_write_seq_regs(ov7251, reg, val, 3); ov7251 707 drivers/media/i2c/ov7251.c static int ov7251_set_gain(struct ov7251 *ov7251, s32 gain) ov7251 716 drivers/media/i2c/ov7251.c return ov7251_write_seq_regs(ov7251, reg, val, 2); ov7251 719 drivers/media/i2c/ov7251.c static int ov7251_set_register_array(struct ov7251 *ov7251, ov7251 727 drivers/media/i2c/ov7251.c ret = ov7251_write_reg(ov7251, settings->reg, settings->val); ov7251 735 drivers/media/i2c/ov7251.c static int ov7251_set_power_on(struct ov7251 *ov7251) ov7251 740 drivers/media/i2c/ov7251.c ret = ov7251_regulators_enable(ov7251); ov7251 744 drivers/media/i2c/ov7251.c ret = clk_prepare_enable(ov7251->xclk); ov7251 746 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "clk prepare enable failed\n"); ov7251 747 drivers/media/i2c/ov7251.c ov7251_regulators_disable(ov7251); ov7251 751 drivers/media/i2c/ov7251.c gpiod_set_value_cansleep(ov7251->enable_gpio, 1); ov7251 755 drivers/media/i2c/ov7251.c DIV_ROUND_UP(ov7251->xclk_freq, 1000)); ov7251 761 drivers/media/i2c/ov7251.c static void ov7251_set_power_off(struct ov7251 *ov7251) ov7251 763 drivers/media/i2c/ov7251.c clk_disable_unprepare(ov7251->xclk); ov7251 764 drivers/media/i2c/ov7251.c gpiod_set_value_cansleep(ov7251->enable_gpio, 0); ov7251 765 drivers/media/i2c/ov7251.c ov7251_regulators_disable(ov7251); ov7251 770 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = to_ov7251(sd); ov7251 773 drivers/media/i2c/ov7251.c mutex_lock(&ov7251->lock); ov7251 776 drivers/media/i2c/ov7251.c if (ov7251->power_on == !!on) ov7251 780 drivers/media/i2c/ov7251.c ret = ov7251_set_power_on(ov7251); ov7251 784 drivers/media/i2c/ov7251.c ret = ov7251_set_register_array(ov7251, ov7251 788 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "could not set init registers\n"); ov7251 789 drivers/media/i2c/ov7251.c ov7251_set_power_off(ov7251); ov7251 793 drivers/media/i2c/ov7251.c ov7251->power_on = true; ov7251 795 drivers/media/i2c/ov7251.c ov7251_set_power_off(ov7251); ov7251 796 drivers/media/i2c/ov7251.c ov7251->power_on = false; ov7251 800 drivers/media/i2c/ov7251.c mutex_unlock(&ov7251->lock); ov7251 805 drivers/media/i2c/ov7251.c static int ov7251_set_hflip(struct ov7251 *ov7251, s32 value) ov7251 807 drivers/media/i2c/ov7251.c u8 val = ov7251->timing_format2; ov7251 815 drivers/media/i2c/ov7251.c ret = ov7251_write_reg(ov7251, OV7251_TIMING_FORMAT2, val); ov7251 817 drivers/media/i2c/ov7251.c ov7251->timing_format2 = val; ov7251 822 drivers/media/i2c/ov7251.c static int ov7251_set_vflip(struct ov7251 *ov7251, s32 value) ov7251 824 drivers/media/i2c/ov7251.c u8 val = ov7251->timing_format1; ov7251 832 drivers/media/i2c/ov7251.c ret = ov7251_write_reg(ov7251, OV7251_TIMING_FORMAT1, val); ov7251 834 drivers/media/i2c/ov7251.c ov7251->timing_format1 = val; ov7251 839 drivers/media/i2c/ov7251.c static int ov7251_set_test_pattern(struct ov7251 *ov7251, s32 value) ov7251 841 drivers/media/i2c/ov7251.c u8 val = ov7251->pre_isp_00; ov7251 849 drivers/media/i2c/ov7251.c ret = ov7251_write_reg(ov7251, OV7251_PRE_ISP_00, val); ov7251 851 drivers/media/i2c/ov7251.c ov7251->pre_isp_00 = val; ov7251 863 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = container_of(ctrl->handler, ov7251 864 drivers/media/i2c/ov7251.c struct ov7251, ctrls); ov7251 869 drivers/media/i2c/ov7251.c if (!ov7251->power_on) ov7251 874 drivers/media/i2c/ov7251.c ret = ov7251_set_exposure(ov7251, ctrl->val); ov7251 877 drivers/media/i2c/ov7251.c ret = ov7251_set_gain(ov7251, ctrl->val); ov7251 880 drivers/media/i2c/ov7251.c ret = ov7251_set_test_pattern(ov7251, ctrl->val); ov7251 883 drivers/media/i2c/ov7251.c ret = ov7251_set_hflip(ov7251, ctrl->val); ov7251 886 drivers/media/i2c/ov7251.c ret = ov7251_set_vflip(ov7251, ctrl->val); ov7251 952 drivers/media/i2c/ov7251.c __ov7251_get_pad_format(struct ov7251 *ov7251, ov7251 959 drivers/media/i2c/ov7251.c return v4l2_subdev_get_try_format(&ov7251->sd, cfg, pad); ov7251 961 drivers/media/i2c/ov7251.c return &ov7251->fmt; ov7251 971 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = to_ov7251(sd); ov7251 973 drivers/media/i2c/ov7251.c mutex_lock(&ov7251->lock); ov7251 974 drivers/media/i2c/ov7251.c format->format = *__ov7251_get_pad_format(ov7251, cfg, format->pad, ov7251 976 drivers/media/i2c/ov7251.c mutex_unlock(&ov7251->lock); ov7251 982 drivers/media/i2c/ov7251.c __ov7251_get_pad_crop(struct ov7251 *ov7251, struct v4l2_subdev_pad_config *cfg, ov7251 987 drivers/media/i2c/ov7251.c return v4l2_subdev_get_try_crop(&ov7251->sd, cfg, pad); ov7251 989 drivers/media/i2c/ov7251.c return &ov7251->crop; ov7251 1001 drivers/media/i2c/ov7251.c ov7251_find_mode_by_ival(struct ov7251 *ov7251, struct v4l2_fract *timeperframe) ov7251 1003 drivers/media/i2c/ov7251.c const struct ov7251_mode_info *mode = ov7251->current_mode; ov7251 1033 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = to_ov7251(sd); ov7251 1039 drivers/media/i2c/ov7251.c mutex_lock(&ov7251->lock); ov7251 1041 drivers/media/i2c/ov7251.c __crop = __ov7251_get_pad_crop(ov7251, cfg, format->pad, format->which); ov7251 1052 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_s_ctrl_int64(ov7251->pixel_clock, ov7251 1057 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_s_ctrl(ov7251->link_freq, ov7251 1062 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_modify_range(ov7251->exposure, ov7251 1068 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_s_ctrl(ov7251->exposure, ov7251 1073 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_s_ctrl(ov7251->gain, 16); ov7251 1077 drivers/media/i2c/ov7251.c ov7251->current_mode = new_mode; ov7251 1080 drivers/media/i2c/ov7251.c __format = __ov7251_get_pad_format(ov7251, cfg, format->pad, ov7251 1095 drivers/media/i2c/ov7251.c mutex_unlock(&ov7251->lock); ov7251 1121 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = to_ov7251(sd); ov7251 1126 drivers/media/i2c/ov7251.c mutex_lock(&ov7251->lock); ov7251 1127 drivers/media/i2c/ov7251.c sel->r = *__ov7251_get_pad_crop(ov7251, cfg, sel->pad, ov7251 1129 drivers/media/i2c/ov7251.c mutex_unlock(&ov7251->lock); ov7251 1136 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = to_ov7251(subdev); ov7251 1139 drivers/media/i2c/ov7251.c mutex_lock(&ov7251->lock); ov7251 1142 drivers/media/i2c/ov7251.c ret = ov7251_set_register_array(ov7251, ov7251 1143 drivers/media/i2c/ov7251.c ov7251->current_mode->data, ov7251 1144 drivers/media/i2c/ov7251.c ov7251->current_mode->data_size); ov7251 1146 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "could not set mode %dx%d\n", ov7251 1147 drivers/media/i2c/ov7251.c ov7251->current_mode->width, ov7251 1148 drivers/media/i2c/ov7251.c ov7251->current_mode->height); ov7251 1151 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_handler_setup(&ov7251->ctrls); ov7251 1153 drivers/media/i2c/ov7251.c dev_err(ov7251->dev, "could not sync v4l2 controls\n"); ov7251 1156 drivers/media/i2c/ov7251.c ret = ov7251_write_reg(ov7251, OV7251_SC_MODE_SELECT, ov7251 1159 drivers/media/i2c/ov7251.c ret = ov7251_write_reg(ov7251, OV7251_SC_MODE_SELECT, ov7251 1164 drivers/media/i2c/ov7251.c mutex_unlock(&ov7251->lock); ov7251 1172 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = to_ov7251(subdev); ov7251 1174 drivers/media/i2c/ov7251.c mutex_lock(&ov7251->lock); ov7251 1175 drivers/media/i2c/ov7251.c fi->interval = ov7251->current_mode->timeperframe; ov7251 1176 drivers/media/i2c/ov7251.c mutex_unlock(&ov7251->lock); ov7251 1184 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = to_ov7251(subdev); ov7251 1188 drivers/media/i2c/ov7251.c mutex_lock(&ov7251->lock); ov7251 1189 drivers/media/i2c/ov7251.c new_mode = ov7251_find_mode_by_ival(ov7251, &fi->interval); ov7251 1191 drivers/media/i2c/ov7251.c if (new_mode != ov7251->current_mode) { ov7251 1192 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_s_ctrl_int64(ov7251->pixel_clock, ov7251 1197 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_s_ctrl(ov7251->link_freq, ov7251 1202 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_modify_range(ov7251->exposure, ov7251 1208 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_s_ctrl(ov7251->exposure, ov7251 1213 drivers/media/i2c/ov7251.c ret = __v4l2_ctrl_s_ctrl(ov7251->gain, 16); ov7251 1217 drivers/media/i2c/ov7251.c ov7251->current_mode = new_mode; ov7251 1220 drivers/media/i2c/ov7251.c fi->interval = ov7251->current_mode->timeperframe; ov7251 1223 drivers/media/i2c/ov7251.c mutex_unlock(&ov7251->lock); ov7251 1258 drivers/media/i2c/ov7251.c struct ov7251 *ov7251; ov7251 1262 drivers/media/i2c/ov7251.c ov7251 = devm_kzalloc(dev, sizeof(struct ov7251), GFP_KERNEL); ov7251 1263 drivers/media/i2c/ov7251.c if (!ov7251) ov7251 1266 drivers/media/i2c/ov7251.c ov7251->i2c_client = client; ov7251 1267 drivers/media/i2c/ov7251.c ov7251->dev = dev; ov7251 1275 drivers/media/i2c/ov7251.c ret = v4l2_fwnode_endpoint_parse(endpoint, &ov7251->ep); ov7251 1282 drivers/media/i2c/ov7251.c if (ov7251->ep.bus_type != V4L2_MBUS_CSI2_DPHY) { ov7251 1284 drivers/media/i2c/ov7251.c ov7251->ep.bus_type, V4L2_MBUS_CSI2_DPHY); ov7251 1289 drivers/media/i2c/ov7251.c ov7251->xclk = devm_clk_get(dev, "xclk"); ov7251 1290 drivers/media/i2c/ov7251.c if (IS_ERR(ov7251->xclk)) { ov7251 1292 drivers/media/i2c/ov7251.c return PTR_ERR(ov7251->xclk); ov7251 1296 drivers/media/i2c/ov7251.c &ov7251->xclk_freq); ov7251 1303 drivers/media/i2c/ov7251.c if (ov7251->xclk_freq < 23760000 || ov7251->xclk_freq > 24240000) { ov7251 1305 drivers/media/i2c/ov7251.c ov7251->xclk_freq); ov7251 1309 drivers/media/i2c/ov7251.c ret = clk_set_rate(ov7251->xclk, ov7251->xclk_freq); ov7251 1315 drivers/media/i2c/ov7251.c ov7251->io_regulator = devm_regulator_get(dev, "vdddo"); ov7251 1316 drivers/media/i2c/ov7251.c if (IS_ERR(ov7251->io_regulator)) { ov7251 1318 drivers/media/i2c/ov7251.c return PTR_ERR(ov7251->io_regulator); ov7251 1321 drivers/media/i2c/ov7251.c ov7251->core_regulator = devm_regulator_get(dev, "vddd"); ov7251 1322 drivers/media/i2c/ov7251.c if (IS_ERR(ov7251->core_regulator)) { ov7251 1324 drivers/media/i2c/ov7251.c return PTR_ERR(ov7251->core_regulator); ov7251 1327 drivers/media/i2c/ov7251.c ov7251->analog_regulator = devm_regulator_get(dev, "vdda"); ov7251 1328 drivers/media/i2c/ov7251.c if (IS_ERR(ov7251->analog_regulator)) { ov7251 1330 drivers/media/i2c/ov7251.c return PTR_ERR(ov7251->analog_regulator); ov7251 1333 drivers/media/i2c/ov7251.c ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH); ov7251 1334 drivers/media/i2c/ov7251.c if (IS_ERR(ov7251->enable_gpio)) { ov7251 1336 drivers/media/i2c/ov7251.c return PTR_ERR(ov7251->enable_gpio); ov7251 1339 drivers/media/i2c/ov7251.c mutex_init(&ov7251->lock); ov7251 1341 drivers/media/i2c/ov7251.c v4l2_ctrl_handler_init(&ov7251->ctrls, 7); ov7251 1342 drivers/media/i2c/ov7251.c ov7251->ctrls.lock = &ov7251->lock; ov7251 1344 drivers/media/i2c/ov7251.c v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, ov7251 1346 drivers/media/i2c/ov7251.c v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, ov7251 1348 drivers/media/i2c/ov7251.c ov7251->exposure = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, ov7251 1350 drivers/media/i2c/ov7251.c ov7251->gain = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, ov7251 1352 drivers/media/i2c/ov7251.c v4l2_ctrl_new_std_menu_items(&ov7251->ctrls, &ov7251_ctrl_ops, ov7251 1356 drivers/media/i2c/ov7251.c ov7251->pixel_clock = v4l2_ctrl_new_std(&ov7251->ctrls, ov7251 1360 drivers/media/i2c/ov7251.c ov7251->link_freq = v4l2_ctrl_new_int_menu(&ov7251->ctrls, ov7251 1365 drivers/media/i2c/ov7251.c if (ov7251->link_freq) ov7251 1366 drivers/media/i2c/ov7251.c ov7251->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; ov7251 1368 drivers/media/i2c/ov7251.c ov7251->sd.ctrl_handler = &ov7251->ctrls; ov7251 1370 drivers/media/i2c/ov7251.c if (ov7251->ctrls.error) { ov7251 1372 drivers/media/i2c/ov7251.c __func__, ov7251->ctrls.error); ov7251 1373 drivers/media/i2c/ov7251.c ret = ov7251->ctrls.error; ov7251 1377 drivers/media/i2c/ov7251.c v4l2_i2c_subdev_init(&ov7251->sd, client, &ov7251_subdev_ops); ov7251 1378 drivers/media/i2c/ov7251.c ov7251->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; ov7251 1379 drivers/media/i2c/ov7251.c ov7251->pad.flags = MEDIA_PAD_FL_SOURCE; ov7251 1380 drivers/media/i2c/ov7251.c ov7251->sd.dev = &client->dev; ov7251 1381 drivers/media/i2c/ov7251.c ov7251->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; ov7251 1383 drivers/media/i2c/ov7251.c ret = media_entity_pads_init(&ov7251->sd.entity, 1, &ov7251->pad); ov7251 1389 drivers/media/i2c/ov7251.c ret = ov7251_s_power(&ov7251->sd, true); ov7251 1395 drivers/media/i2c/ov7251.c ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_HIGH, &chip_id_high); ov7251 1401 drivers/media/i2c/ov7251.c ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_LOW, &chip_id_low); ov7251 1408 drivers/media/i2c/ov7251.c ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev); ov7251 1424 drivers/media/i2c/ov7251.c ret = ov7251_read_reg(ov7251, OV7251_PRE_ISP_00, ov7251 1425 drivers/media/i2c/ov7251.c &ov7251->pre_isp_00); ov7251 1432 drivers/media/i2c/ov7251.c ret = ov7251_read_reg(ov7251, OV7251_TIMING_FORMAT1, ov7251 1433 drivers/media/i2c/ov7251.c &ov7251->timing_format1); ov7251 1440 drivers/media/i2c/ov7251.c ret = ov7251_read_reg(ov7251, OV7251_TIMING_FORMAT2, ov7251 1441 drivers/media/i2c/ov7251.c &ov7251->timing_format2); ov7251 1448 drivers/media/i2c/ov7251.c ov7251_s_power(&ov7251->sd, false); ov7251 1450 drivers/media/i2c/ov7251.c ret = v4l2_async_register_subdev(&ov7251->sd); ov7251 1456 drivers/media/i2c/ov7251.c ov7251_entity_init_cfg(&ov7251->sd, NULL); ov7251 1461 drivers/media/i2c/ov7251.c ov7251_s_power(&ov7251->sd, false); ov7251 1463 drivers/media/i2c/ov7251.c media_entity_cleanup(&ov7251->sd.entity); ov7251 1465 drivers/media/i2c/ov7251.c v4l2_ctrl_handler_free(&ov7251->ctrls); ov7251 1466 drivers/media/i2c/ov7251.c mutex_destroy(&ov7251->lock); ov7251 1474 drivers/media/i2c/ov7251.c struct ov7251 *ov7251 = to_ov7251(sd); ov7251 1476 drivers/media/i2c/ov7251.c v4l2_async_unregister_subdev(&ov7251->sd); ov7251 1477 drivers/media/i2c/ov7251.c media_entity_cleanup(&ov7251->sd.entity); ov7251 1478 drivers/media/i2c/ov7251.c v4l2_ctrl_handler_free(&ov7251->ctrls); ov7251 1479 drivers/media/i2c/ov7251.c mutex_destroy(&ov7251->lock);