Lines Matching +full:camera +full:- +full:command +full:- +full:set

1 // SPDX-License-Identifier: GPL-2.0-only
19 #include <linux/mtd/spi-nor.h>
26 #include <media/v4l2-async.h>
27 #include <media/v4l2-cci.h>
28 #include <media/v4l2-ctrls.h>
29 #include <media/v4l2-device.h>
30 #include <media/v4l2-fwnode.h>
31 #include <media/v4l2-subdev.h>
129 * enum thp7312_focus_state - State of the focus handler
133 * @THP7312_FOCUS_STATE_AUTO: Continuous auto-focus
136 * @THP7312_FOCUS_STATE_ONESHOT: One-shot auto-focus
148 * manual -> auto [label="FOCUS_AUTO <- true"]
149 * locked -> auto [label="FOCUS_AUTO <- true"]
150 * oneshot -> auto [label="FOCUS_AUTO <- true"]
151 * auto -> locked [label="FOCUS_AUTO <- false"]
153 * locked -> manual [label="FOCUS_ABSOLUTE <- *"]
154 * oneshot -> manual [label="FOCUS_ABSOLUTE <- *"]
156 * manual -> oneshot [label="FOCUS_START <- *"]
157 * locked -> oneshot [label="FOCUS_START <- *"]
196 "vddgpio-0",
197 "vddgpio-1",
318 if (!nearest && (mode->width != width || mode->height != height)) in thp7312_find_mode()
335 for (rate = mode->rates; rate->fps && best_delta; ++rate) { in thp7312_find_rate()
336 unsigned int delta = abs(rate->fps - fps); in thp7312_find_rate()
350 /* -----------------------------------------------------------------------------
358 timeout_us, false, (dev)->regmap, addr, \
371 * data-lanes array, so we need to do a conversion. Do this in the same in thp7312_map_data_lanes()
372 * pass as validating data-lanes. in thp7312_map_data_lanes()
376 return -EINVAL; in thp7312_map_data_lanes()
379 return -EINVAL; in thp7312_map_data_lanes()
384 * data-lanes is 1-indexed while the field position in the in thp7312_map_data_lanes()
385 * register is 0-indexed. in thp7312_map_data_lanes()
387 val |= i << ((lanes[i] - 1) * 2); in thp7312_map_data_lanes()
397 struct device *dev = thp7312->dev; in thp7312_set_mipi_lanes()
401 cci_write(thp7312->regmap, TH7312_REG_CUSTOM_MIPI_RD, in thp7312_set_mipi_lanes()
402 thp7312->sensors[0].lane_remap, &ret); in thp7312_set_mipi_lanes()
403 cci_write(thp7312->regmap, TH7312_REG_CUSTOM_MIPI_TD, in thp7312_set_mipi_lanes()
404 thp7312->lane_remap, &ret); in thp7312_set_mipi_lanes()
405 cci_write(thp7312->regmap, TH7312_REG_CUSTOM_MIPI_SET, 1, &ret); in thp7312_set_mipi_lanes()
424 struct device *dev = thp7312->dev; in thp7312_change_mode()
435 cci_write(thp7312->regmap, THP7312_REG_VIDEO_IMAGE_SIZE, in thp7312_change_mode()
436 mode->reg_image_size, &ret); in thp7312_change_mode()
437 cci_write(thp7312->regmap, THP7312_REG_VIDEO_FRAME_RATE_MODE, in thp7312_change_mode()
438 rate->reg_frame_rate_mode, &ret); in thp7312_change_mode()
439 cci_write(thp7312->regmap, THP7312_REG_JPEG_COMPRESSION_FACTOR, 0x5e, in thp7312_change_mode()
441 cci_write(thp7312->regmap, THP7312_REG_SET_DRIVING_MODE, 0x01, &ret); in thp7312_change_mode()
461 switch (format->code) { in thp7312_set_framefmt()
472 return -EINVAL; in thp7312_set_framefmt()
475 return cci_write(thp7312->regmap, in thp7312_set_framefmt()
495 mode = thp7312_find_mode(fmt->width, fmt->height, false); in thp7312_init_mode()
496 rate = thp7312_find_rate(mode, interval->denominator, false); in thp7312_init_mode()
499 return -EINVAL; in thp7312_init_mode()
510 return cci_write(thp7312->regmap, THP7312_REG_SET_OUTPUT_ENABLE, in thp7312_stream_enable()
517 struct device *dev = thp7312->dev; in thp7312_check_status_stream_mode()
522 ret = cci_read(thp7312->regmap, THP7312_REG_CAMERA_STATUS, in thp7312_check_status_stream_mode()
528 dev_dbg(dev, "Camera initialization done\n"); in thp7312_check_status_stream_mode()
533 dev_err(dev, "Invalid camera status %llx\n", status); in thp7312_check_status_stream_mode()
534 return -EINVAL; in thp7312_check_status_stream_mode()
537 dev_dbg(dev, "Camera initializing...\n"); in thp7312_check_status_stream_mode()
548 gpiod_set_value_cansleep(thp7312->reset_gpio, 1); in thp7312_reset()
554 rate = clk_get_rate(thp7312->iclk); in thp7312_reset()
557 gpiod_set_value_cansleep(thp7312->reset_gpio, 0); in thp7312_reset()
568 /* -----------------------------------------------------------------------------
574 regulator_bulk_disable(ARRAY_SIZE(thp7312->supplies), thp7312->supplies); in __thp7312_power_off()
575 clk_disable_unprepare(thp7312->iclk); in __thp7312_power_off()
585 struct device *dev = thp7312->dev; in __thp7312_power_on()
588 ret = regulator_bulk_enable(ARRAY_SIZE(thp7312->supplies), in __thp7312_power_on()
589 thp7312->supplies); in __thp7312_power_on()
593 ret = clk_prepare_enable(thp7312->iclk); in __thp7312_power_on()
596 regulator_bulk_disable(ARRAY_SIZE(thp7312->supplies), in __thp7312_power_on()
597 thp7312->supplies); in __thp7312_power_on()
640 thp7312->ctrls_applied = false; in thp7312_pm_runtime_suspend()
658 /* -----------------------------------------------------------------------------
678 if (code->index >= ARRAY_SIZE(thp7312_colour_fmts)) in thp7312_enum_mbus_code()
679 return -EINVAL; in thp7312_enum_mbus_code()
681 code->code = thp7312_colour_fmts[code->index]; in thp7312_enum_mbus_code()
690 if (!thp7312_find_bus_code(fse->code)) in thp7312_enum_frame_size()
691 return -EINVAL; in thp7312_enum_frame_size()
693 if (fse->index >= ARRAY_SIZE(thp7312_mode_info_data)) in thp7312_enum_frame_size()
694 return -EINVAL; in thp7312_enum_frame_size()
696 fse->min_width = thp7312_mode_info_data[fse->index].width; in thp7312_enum_frame_size()
697 fse->max_width = fse->min_width; in thp7312_enum_frame_size()
698 fse->min_height = thp7312_mode_info_data[fse->index].height; in thp7312_enum_frame_size()
699 fse->max_height = fse->min_height; in thp7312_enum_frame_size()
710 unsigned int index = fie->index; in thp7312_enum_frame_interval()
712 if (!thp7312_find_bus_code(fie->code)) in thp7312_enum_frame_interval()
713 return -EINVAL; in thp7312_enum_frame_interval()
715 mode = thp7312_find_mode(fie->width, fie->height, false); in thp7312_enum_frame_interval()
717 return -EINVAL; in thp7312_enum_frame_interval()
719 for (rate = mode->rates; rate->fps; ++rate, --index) { in thp7312_enum_frame_interval()
721 fie->interval.numerator = 1; in thp7312_enum_frame_interval()
722 fie->interval.denominator = rate->fps; in thp7312_enum_frame_interval()
728 return -EINVAL; in thp7312_enum_frame_interval()
736 struct v4l2_mbus_framefmt *mbus_fmt = &format->format; in thp7312_set_fmt()
741 if (!thp7312_find_bus_code(mbus_fmt->code)) in thp7312_set_fmt()
742 mbus_fmt->code = thp7312_colour_fmts[0]; in thp7312_set_fmt()
744 mode = thp7312_find_mode(mbus_fmt->width, mbus_fmt->height, true); in thp7312_set_fmt()
748 fmt->code = mbus_fmt->code; in thp7312_set_fmt()
749 fmt->width = mode->width; in thp7312_set_fmt()
750 fmt->height = mode->height; in thp7312_set_fmt()
751 fmt->colorspace = V4L2_COLORSPACE_SRGB; in thp7312_set_fmt()
752 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in thp7312_set_fmt()
753 fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; in thp7312_set_fmt()
754 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); in thp7312_set_fmt()
759 interval->numerator = 1; in thp7312_set_fmt()
760 interval->denominator = mode->rates[0].fps; in thp7312_set_fmt()
762 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) in thp7312_set_fmt()
763 thp7312->link_freq = mode->rates[0].link_freq; in thp7312_set_fmt()
780 fps = fi->interval.numerator in thp7312_set_frame_interval()
781 ? DIV_ROUND_CLOSEST(fi->interval.denominator, fi->interval.numerator) in thp7312_set_frame_interval()
785 mode = thp7312_find_mode(fmt->width, fmt->height, false); in thp7312_set_frame_interval()
789 interval->numerator = 1; in thp7312_set_frame_interval()
790 interval->denominator = rate->fps; in thp7312_set_frame_interval()
792 if (fi->which == V4L2_SUBDEV_FORMAT_ACTIVE) in thp7312_set_frame_interval()
793 thp7312->link_freq = rate->link_freq; in thp7312_set_frame_interval()
795 fi->interval = *interval; in thp7312_set_frame_interval()
811 pm_runtime_mark_last_busy(thp7312->dev); in thp7312_s_stream()
812 pm_runtime_put_autosuspend(thp7312->dev); in thp7312_s_stream()
819 ret = pm_runtime_resume_and_get(thp7312->dev); in thp7312_s_stream()
827 if (!thp7312->ctrls_applied) { in thp7312_s_stream()
828 ret = __v4l2_ctrl_handler_setup(&thp7312->ctrl_handler); in thp7312_s_stream()
832 thp7312->ctrls_applied = true; in thp7312_s_stream()
842 pm_runtime_mark_last_busy(thp7312->dev); in thp7312_s_stream()
843 pm_runtime_put_autosuspend(thp7312->dev); in thp7312_s_stream()
864 fmt->code = MEDIA_BUS_FMT_YUYV8_1X16; in thp7312_init_state()
865 fmt->colorspace = V4L2_COLORSPACE_SRGB; in thp7312_init_state()
866 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in thp7312_init_state()
867 fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; in thp7312_init_state()
868 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); in thp7312_init_state()
869 fmt->width = default_mode->width; in thp7312_init_state()
870 fmt->height = default_mode->height; in thp7312_init_state()
871 fmt->field = V4L2_FIELD_NONE; in thp7312_init_state()
873 interval->numerator = 1; in thp7312_init_state()
874 interval->denominator = default_mode->rates[0].fps; in thp7312_init_state()
907 /* -----------------------------------------------------------------------------
913 return container_of(ctrl->handler, struct thp7312_device, ctrl_handler); in to_thp7312_from_ctrl()
926 enum thp7312_focus_state new_state = thp7312->focus_state; in thp7312_set_focus()
933 if (thp7312->focus_absolute->is_new) { in thp7312_set_focus()
936 value = thp7312_focus_values[thp7312->focus_absolute->val]; in thp7312_set_focus()
938 ret = cci_write(thp7312->regmap, in thp7312_set_focus()
945 switch (thp7312->focus_state) { in thp7312_set_focus()
948 if (thp7312->focus_auto->val) in thp7312_set_focus()
950 else if (thp7312->focus_start->is_new) in thp7312_set_focus()
955 if (!thp7312->focus_auto->val) in thp7312_set_focus()
960 if (thp7312->focus_auto->val) in thp7312_set_focus()
962 else if (thp7312->focus_start->is_new) in thp7312_set_focus()
964 else if (thp7312->focus_absolute->is_new) in thp7312_set_focus()
969 if (thp7312->focus_auto->val) in thp7312_set_focus()
971 else if (thp7312->focus_start->is_new) in thp7312_set_focus()
973 else if (thp7312->focus_absolute->is_new) in thp7312_set_focus()
980 * one-shot focus is requested, there's nothing new to program to the in thp7312_set_focus()
983 if (thp7312->focus_state == new_state && in thp7312_set_focus()
984 !thp7312->focus_method->is_new && !thp7312->focus_start->is_new) in thp7312_set_focus()
990 switch (thp7312->focus_method->val) { in thp7312_set_focus()
1023 cci_write(thp7312->regmap, THP7312_REG_AF_SETTING, af_setting, &ret); in thp7312_set_focus()
1026 (thp7312->focus_state == THP7312_FOCUS_STATE_AUTO || in thp7312_set_focus()
1027 thp7312->focus_state == THP7312_FOCUS_STATE_ONESHOT)) { in thp7312_set_focus()
1029 cci_write(thp7312->regmap, THP7312_REG_AF_CONTROL, in thp7312_set_focus()
1033 cci_write(thp7312->regmap, THP7312_REG_AF_CONTROL, af_control, &ret); in thp7312_set_focus()
1038 thp7312->focus_state = new_state; in thp7312_set_focus()
1049 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) in thp7312_s_ctrl()
1050 return -EINVAL; in thp7312_s_ctrl()
1052 if (!pm_runtime_get_if_active(thp7312->dev)) in thp7312_s_ctrl()
1055 switch (ctrl->id) { in thp7312_s_ctrl()
1057 cci_write(thp7312->regmap, THP7312_REG_BRIGHTNESS, in thp7312_s_ctrl()
1058 ctrl->val + 10, &ret); in thp7312_s_ctrl()
1063 cci_write(thp7312->regmap, THP7312_REG_AE_FIX_FRAME_RATE, in thp7312_s_ctrl()
1064 ctrl->val ? 0 : 1, &ret); in thp7312_s_ctrl()
1076 value = (thp7312->hflip->val ? THP7312_REG_FLIP_MIRROR_MIRROR : 0) in thp7312_s_ctrl()
1077 | (thp7312->vflip->val ? THP7312_REG_FLIP_MIRROR_FLIP : 0); in thp7312_s_ctrl()
1079 cci_write(thp7312->regmap, THP7312_REG_FLIP_MIRROR, value, &ret); in thp7312_s_ctrl()
1084 value = thp7312->noise_reduction_auto->val ? 0 in thp7312_s_ctrl()
1086 thp7312->noise_reduction_absolute->val; in thp7312_s_ctrl()
1088 cci_write(thp7312->regmap, THP7312_REG_NOISE_REDUCTION, value, in thp7312_s_ctrl()
1093 value = ctrl->val ? THP7312_WB_MODE_AUTO : THP7312_WB_MODE_MANUAL; in thp7312_s_ctrl()
1095 cci_write(thp7312->regmap, THP7312_REG_WB_MODE, value, &ret); in thp7312_s_ctrl()
1099 cci_write(thp7312->regmap, THP7312_REG_MANUAL_WB_RED_GAIN, in thp7312_s_ctrl()
1100 ctrl->val, &ret); in thp7312_s_ctrl()
1104 cci_write(thp7312->regmap, THP7312_REG_MANUAL_WB_BLUE_GAIN, in thp7312_s_ctrl()
1105 ctrl->val, &ret); in thp7312_s_ctrl()
1109 cci_write(thp7312->regmap, THP7312_REG_AE_EXPOSURE_COMPENSATION, in thp7312_s_ctrl()
1110 ctrl->val, &ret); in thp7312_s_ctrl()
1114 if (ctrl->val == V4L2_CID_POWER_LINE_FREQUENCY_60HZ) { in thp7312_s_ctrl()
1116 } else if (ctrl->val == V4L2_CID_POWER_LINE_FREQUENCY_50HZ) { in thp7312_s_ctrl()
1119 if (thp7312->fw_version == THP7312_FW_VERSION(40, 3)) { in thp7312_s_ctrl()
1127 cci_write(thp7312->regmap, THP7312_REG_AE_FLICKER_MODE, in thp7312_s_ctrl()
1132 cci_write(thp7312->regmap, THP7312_REG_SATURATION, in thp7312_s_ctrl()
1133 ctrl->val, &ret); in thp7312_s_ctrl()
1137 cci_write(thp7312->regmap, THP7312_REG_CONTRAST, in thp7312_s_ctrl()
1138 ctrl->val, &ret); in thp7312_s_ctrl()
1142 cci_write(thp7312->regmap, THP7312_REG_SHARPNESS, in thp7312_s_ctrl()
1143 ctrl->val, &ret); in thp7312_s_ctrl()
1150 pm_runtime_mark_last_busy(thp7312->dev); in thp7312_s_ctrl()
1151 pm_runtime_put_autosuspend(thp7312->dev); in thp7312_s_ctrl()
1161 * Refer to Documentation/userspace-api/media/drivers/thp7312.rst for details.
1166 .name = "Auto-Focus Method",
1177 .name = "Auto-Focus Method",
1217 -2000, -1667, -1333, -1000, -667, -333, 0, 333, 667, 1000, 1333, 1667, 2000
1222 struct v4l2_ctrl_handler *hdl = &thp7312->ctrl_handler; in thp7312_init_controls()
1223 struct device *dev = thp7312->dev; in thp7312_init_controls()
1232 * Check what auto-focus methods the connected sensor supports, if any. in thp7312_init_controls()
1236 if (thp7312->fw_version >= THP7312_FW_VERSION(90, 3)) { in thp7312_init_controls()
1239 ret = cci_read(thp7312->regmap, THP7312_REG_AF_SUPPORT, &val, in thp7312_init_controls()
1263 thp7312->focus_state = THP7312_FOCUS_STATE_MANUAL; in thp7312_init_controls()
1265 thp7312->focus_auto = in thp7312_init_controls()
1269 thp7312->focus_absolute = in thp7312_init_controls()
1274 thp7312->focus_method = in thp7312_init_controls()
1276 thp7312->focus_start = in thp7312_init_controls()
1281 v4l2_ctrl_cluster(4, &thp7312->focus_auto); in thp7312_init_controls()
1294 -10, 10, 1, 0); in thp7312_init_controls()
1302 thp7312->hflip = v4l2_ctrl_new_std(hdl, &thp7312_ctrl_ops, in thp7312_init_controls()
1304 thp7312->vflip = v4l2_ctrl_new_std(hdl, &thp7312_ctrl_ops, in thp7312_init_controls()
1307 v4l2_ctrl_cluster(2, &thp7312->hflip); in thp7312_init_controls()
1311 ARRAY_SIZE(exp_bias_qmenu) - 1, in thp7312_init_controls()
1319 thp7312->link_freq = thp7312_mode_info_data[0].rates[0].link_freq; in thp7312_init_controls()
1323 &thp7312->link_freq); in thp7312_init_controls()
1325 /* Set properties from fwnode (e.g. rotation, orientation). */ in thp7312_init_controls()
1345 if (ctrl_cfg->id == V4L2_CID_THP7312_NOISE_REDUCTION_AUTO) in thp7312_init_controls()
1346 thp7312->noise_reduction_auto = ctrl; in thp7312_init_controls()
1347 else if (ctrl_cfg->id == V4L2_CID_THP7312_NOISE_REDUCTION_ABSOLUTE) in thp7312_init_controls()
1348 thp7312->noise_reduction_absolute = ctrl; in thp7312_init_controls()
1351 v4l2_ctrl_cluster(2, &thp7312->noise_reduction_auto); in thp7312_init_controls()
1353 if (hdl->error) { in thp7312_init_controls()
1355 ret = hdl->error; in thp7312_init_controls()
1359 link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in thp7312_init_controls()
1368 /* -----------------------------------------------------------------------------
1374 * variable-size "header". Both are stored in flash memory.
1407 * Command ID FF700F
1410 * BB BB BB: (write size - 1)
1416 * THP7312 Calculate CRC command
1417 * Command ID: FF70 09
1420 * BB BB BB: (calculate size - 1)
1435 cci_read(thp7312->regmap, THP7312_REG_FIRMWARE_VERSION_1, &val, &ret); in thp7312_read_firmware_version()
1438 cci_read(thp7312->regmap, THP7312_REG_FIRMWARE_VERSION_2, &val, &ret); in thp7312_read_firmware_version()
1441 thp7312->fw_version = THP7312_FW_VERSION(major, minor); in thp7312_read_firmware_version()
1448 struct i2c_client *client = to_i2c_client(thp7312->dev); in thp7312_write_buf()
1458 struct device *dev = thp7312->dev; in __thp7312_flash_reg_write()
1465 return -EINVAL; in __thp7312_flash_reg_write()
1493 struct i2c_client *client = to_i2c_client(thp7312->dev); in __thp7312_flash_reg_read()
1501 msgs[0].addr = client->addr; in __thp7312_flash_reg_read()
1506 msgs[1].addr = client->addr; in __thp7312_flash_reg_read()
1511 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in __thp7312_flash_reg_read()
1524 struct device *dev = thp7312->dev; in thp7312_fw_prepare_config()
1527 ret = cci_write(thp7312->regmap, THP7312_REG_FW_MEMORY_IO_SETTING, in thp7312_fw_prepare_config()
1530 dev_err(dev, "Failed to set flash memory I/O\n"); in thp7312_fw_prepare_config()
1534 /* Set max drivability. */ in thp7312_fw_prepare_config()
1535 ret = cci_write(thp7312->regmap, THP7312_REG_FW_DRIVABILITY, 0x00777777, in thp7312_fw_prepare_config()
1538 dev_err(dev, "Failed to set drivability: %d\n", ret); in thp7312_fw_prepare_config()
1547 struct device *dev = thp7312->dev; in thp7312_fw_prepare_check()
1566 struct device *dev = thp7312->dev; in thp7312_fw_prepare_reset()
1569 ret = cci_write(thp7312->regmap, THP7312_REG_FW_RESET_FLASH, 0x81, NULL); in thp7312_fw_prepare_reset()
1581 struct device *dev = thp7312->dev; in thp7312_flash_erase()
1630 struct device *dev = thp7312->dev; in thp7312_write_download_data_by_unit()
1631 u8 *write_buf = thp7312->fw_write_buf; in thp7312_write_download_data_by_unit()
1643 * Command ID (address to download): 0x0000 - 0x7fff in thp7312_write_download_data_by_unit()
1656 struct device *dev = thp7312->dev; in thp7312_fw_load_to_ram()
1671 ret = cci_write(thp7312->regmap, THP7312_REG_FW_DEST_BANK_ADDR, in thp7312_fw_load_to_ram()
1698 size -= chunk_size; in thp7312_fw_load_to_ram()
1708 u8 command[sizeof(thp7312_cmd_write_ram_to_flash) + 6]; in thp7312_fw_write_to_flash() local
1713 memcpy(command, thp7312_cmd_write_ram_to_flash, cmd_size); in thp7312_fw_write_to_flash()
1715 command[cmd_size] = (dest & 0xff0000) >> 16; in thp7312_fw_write_to_flash()
1716 command[cmd_size + 1] = (dest & 0x00ff00) >> 8; in thp7312_fw_write_to_flash()
1717 command[cmd_size + 2] = (dest & 0x0000ff); in thp7312_fw_write_to_flash()
1718 command[cmd_size + 3] = ((write_size - 1) & 0xff0000) >> 16; in thp7312_fw_write_to_flash()
1719 command[cmd_size + 4] = ((write_size - 1) & 0x00ff00) >> 8; in thp7312_fw_write_to_flash()
1720 command[cmd_size + 5] = ((write_size - 1) & 0x0000ff); in thp7312_fw_write_to_flash()
1722 ret = thp7312_write_buf(thp7312, command, sizeof(command)); in thp7312_fw_write_to_flash()
1728 ret = cci_read(thp7312->regmap, THP7312_REG_FW_VERIFY_RESULT, &val, in thp7312_fw_write_to_flash()
1739 struct device *dev = thp7312->dev; in thp7312_fw_check_crc()
1740 u16 header_size = fw_size - THP7312_FW_RAM_SIZE; in thp7312_fw_check_crc()
1741 u8 command[sizeof(thp7312_cmd_calc_crc) + 6]; in thp7312_fw_check_crc() local
1743 u32 size = THP7312_FW_RAM_SIZE - 4; in thp7312_fw_check_crc()
1748 memcpy(command, thp7312_cmd_calc_crc, cmd_size); in thp7312_fw_check_crc()
1750 command[cmd_size] = 0; in thp7312_fw_check_crc()
1751 command[cmd_size + 1] = (header_size >> 8) & 0xff; in thp7312_fw_check_crc()
1752 command[cmd_size + 2] = header_size & 0xff; in thp7312_fw_check_crc()
1754 command[cmd_size + 3] = (size >> 16) & 0xff; in thp7312_fw_check_crc()
1755 command[cmd_size + 4] = (size >> 8) & 0xff; in thp7312_fw_check_crc()
1756 command[cmd_size + 5] = size & 0xff; in thp7312_fw_check_crc()
1758 ret = thp7312_write_buf(thp7312, command, sizeof(command)); in thp7312_fw_check_crc()
1764 fw_crc = get_unaligned_be32(&fw_data[fw_size - 4]); in thp7312_fw_check_crc()
1766 ret = cci_read(thp7312->regmap, THP7312_REG_FW_CRC_RESULT, &crc, NULL); in thp7312_fw_check_crc()
1782 struct thp7312_device *thp7312 = fw_upload->dd_handle; in thp7312_fw_prepare()
1783 struct device *dev = thp7312->dev; in thp7312_fw_prepare()
1786 mutex_lock(&thp7312->fw_lock); in thp7312_fw_prepare()
1787 thp7312->fw_cancel = false; in thp7312_fw_prepare()
1788 mutex_unlock(&thp7312->fw_lock); in thp7312_fw_prepare()
1808 mutex_lock(&thp7312->fw_lock); in thp7312_fw_prepare()
1809 ret = thp7312->fw_cancel ? FW_UPLOAD_ERR_CANCELED : FW_UPLOAD_ERR_NONE; in thp7312_fw_prepare()
1810 mutex_unlock(&thp7312->fw_lock); in thp7312_fw_prepare()
1819 struct thp7312_device *thp7312 = fw_upload->dd_handle; in thp7312_fw_write()
1820 struct device *dev = thp7312->dev; in thp7312_fw_write()
1821 u16 header_size = size - THP7312_FW_RAM_SIZE; in thp7312_fw_write()
1825 mutex_lock(&thp7312->fw_lock); in thp7312_fw_write()
1826 cancel = thp7312->fw_cancel; in thp7312_fw_write()
1827 mutex_unlock(&thp7312->fw_lock); in thp7312_fw_write()
1848 ret = thp7312_fw_write_to_flash(thp7312, 0x20000, header_size - 1); in thp7312_fw_write()
1868 * This may be called asynchronously with an on-going update. All other
1875 struct thp7312_device *thp7312 = fw_upload->dd_handle; in thp7312_fw_cancel()
1877 mutex_lock(&thp7312->fw_lock); in thp7312_fw_cancel()
1878 thp7312->fw_cancel = true; in thp7312_fw_cancel()
1879 mutex_unlock(&thp7312->fw_lock); in thp7312_fw_cancel()
1891 struct device *dev = thp7312->dev; in thp7312_register_flash_mode()
1898 mutex_init(&thp7312->fw_lock); in thp7312_register_flash_mode()
1900 thp7312->fw_write_buf = devm_kzalloc(dev, THP7312_FW_DOWNLOAD_UNIT + 2, in thp7312_register_flash_mode()
1902 if (!thp7312->fw_write_buf) in thp7312_register_flash_mode()
1903 return -ENOMEM; in thp7312_register_flash_mode()
1909 ret = cci_read(thp7312->regmap, THP7312_REG_FW_STATUS, &val, NULL); in thp7312_register_flash_mode()
1911 dev_err_probe(dev, ret, "Camera status read failed\n"); in thp7312_register_flash_mode()
1915 fwl = firmware_upload_register(THIS_MODULE, dev, "thp7312-firmware", in thp7312_register_flash_mode()
1923 thp7312->fwl = fwl; in thp7312_register_flash_mode()
1931 /* -----------------------------------------------------------------------------
1939 for (i = 0; i < ARRAY_SIZE(thp7312->supplies); i++) in thp7312_get_regulators()
1940 thp7312->supplies[i].supply = thp7312_supply_name[i]; in thp7312_get_regulators()
1942 return devm_regulator_bulk_get(thp7312->dev, in thp7312_get_regulators()
1943 ARRAY_SIZE(thp7312->supplies), in thp7312_get_regulators()
1944 thp7312->supplies); in thp7312_get_regulators()
1950 struct device *dev = thp7312->dev; in thp7312_sensor_parse_dt()
1963 return -EINVAL; in thp7312_sensor_parse_dt()
1966 if (reg >= ARRAY_SIZE(thp7312->sensors)) { in thp7312_sensor_parse_dt()
1967 dev_err(dev, "Out-of-bounds 'reg' value %u\n", reg); in thp7312_sensor_parse_dt()
1968 return -EINVAL; in thp7312_sensor_parse_dt()
1971 sensor = &thp7312->sensors[reg]; in thp7312_sensor_parse_dt()
1972 if (sensor->info) { in thp7312_sensor_parse_dt()
1974 return -EINVAL; in thp7312_sensor_parse_dt()
1980 return -EINVAL; in thp7312_sensor_parse_dt()
1987 if (!strcmp(info->model, model)) { in thp7312_sensor_parse_dt()
1988 sensor->info = info; in thp7312_sensor_parse_dt()
1993 if (!sensor->info) { in thp7312_sensor_parse_dt()
1995 return -EINVAL; in thp7312_sensor_parse_dt()
1998 ret = fwnode_property_read_u32_array(node, "data-lanes", values, in thp7312_sensor_parse_dt()
2001 dev_err(dev, "Failed to read property data-lanes: %d\n", ret); in thp7312_sensor_parse_dt()
2008 ret = thp7312_map_data_lanes(&sensor->lane_remap, data_lanes, in thp7312_sensor_parse_dt()
2011 dev_err(dev, "Invalid sensor@%u data-lanes value\n", reg); in thp7312_sensor_parse_dt()
2023 struct device *dev = thp7312->dev; in thp7312_parse_dt()
2032 return dev_err_probe(dev, -EINVAL, "Endpoint node not found\n"); in thp7312_parse_dt()
2039 ret = thp7312_map_data_lanes(&thp7312->lane_remap, in thp7312_parse_dt()
2043 dev_err(dev, "Invalid data-lanes value\n"); in thp7312_parse_dt()
2048 * The thine,boot-mode property is optional and default to in thp7312_parse_dt()
2051 thp7312->boot_mode = THP7312_BOOT_MODE_SPI_MASTER; in thp7312_parse_dt()
2052 ret = device_property_read_u32(dev, "thine,boot-mode", in thp7312_parse_dt()
2053 &thp7312->boot_mode); in thp7312_parse_dt()
2054 if (ret && ret != -EINVAL) in thp7312_parse_dt()
2056 "thine,boot-mode"); in thp7312_parse_dt()
2058 if (thp7312->boot_mode != THP7312_BOOT_MODE_2WIRE_SLAVE && in thp7312_parse_dt()
2059 thp7312->boot_mode != THP7312_BOOT_MODE_SPI_MASTER) in thp7312_parse_dt()
2060 return dev_err_probe(dev, -EINVAL, "Invalid '%s' value %u\n", in thp7312_parse_dt()
2061 "thine,boot-mode", thp7312->boot_mode); in thp7312_parse_dt()
2067 return -EINVAL; in thp7312_parse_dt()
2081 return -EINVAL; in thp7312_parse_dt()
2089 struct device *dev = &client->dev; in thp7312_probe()
2095 return -ENOMEM; in thp7312_probe()
2097 thp7312->dev = dev; in thp7312_probe()
2099 thp7312->regmap = devm_cci_regmap_init_i2c(client, 16); in thp7312_probe()
2100 if (IS_ERR(thp7312->regmap)) in thp7312_probe()
2101 return dev_err_probe(dev, PTR_ERR(thp7312->regmap), in thp7312_probe()
2112 thp7312->iclk = devm_clk_get(dev, NULL); in thp7312_probe()
2113 if (IS_ERR(thp7312->iclk)) in thp7312_probe()
2114 return dev_err_probe(dev, PTR_ERR(thp7312->iclk), in thp7312_probe()
2117 thp7312->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); in thp7312_probe()
2118 if (IS_ERR(thp7312->reset_gpio)) in thp7312_probe()
2119 return dev_err_probe(dev, PTR_ERR(thp7312->reset_gpio), in thp7312_probe()
2122 if (thp7312->boot_mode == THP7312_BOOT_MODE_2WIRE_SLAVE) in thp7312_probe()
2125 v4l2_i2c_subdev_init(&thp7312->sd, client, &thp7312_subdev_ops); in thp7312_probe()
2126 thp7312->sd.internal_ops = &thp7312_internal_ops; in thp7312_probe()
2127 thp7312->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in thp7312_probe()
2128 thp7312->pad.flags = MEDIA_PAD_FL_SOURCE; in thp7312_probe()
2129 thp7312->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in thp7312_probe()
2131 ret = media_entity_pads_init(&thp7312->sd.entity, 1, &thp7312->pad); in thp7312_probe()
2146 dev_err(dev, "Camera is not found\n"); in thp7312_probe()
2156 thp7312->sd.ctrl_handler = &thp7312->ctrl_handler; in thp7312_probe()
2157 thp7312->sd.state_lock = thp7312->ctrl_handler.lock; in thp7312_probe()
2159 ret = v4l2_subdev_init_finalize(&thp7312->sd); in thp7312_probe()
2176 ret = v4l2_async_register_subdev(&thp7312->sd); in thp7312_probe()
2190 THP7312_FW_VERSION_MAJOR(thp7312->fw_version), in thp7312_probe()
2191 THP7312_FW_VERSION_MINOR(thp7312->fw_version)); in thp7312_probe()
2198 v4l2_subdev_cleanup(&thp7312->sd); in thp7312_probe()
2200 v4l2_ctrl_handler_free(&thp7312->ctrl_handler); in thp7312_probe()
2204 media_entity_cleanup(&thp7312->sd.entity); in thp7312_probe()
2213 if (thp7312->boot_mode == THP7312_BOOT_MODE_2WIRE_SLAVE) { in thp7312_remove()
2214 firmware_upload_unregister(thp7312->fwl); in thp7312_remove()
2219 v4l2_async_unregister_subdev(&thp7312->sd); in thp7312_remove()
2220 v4l2_subdev_cleanup(&thp7312->sd); in thp7312_remove()
2221 media_entity_cleanup(&thp7312->sd.entity); in thp7312_remove()
2222 v4l2_ctrl_handler_free(&thp7312->ctrl_handler); in thp7312_remove()
2228 pm_runtime_disable(thp7312->dev); in thp7312_remove()
2229 if (!pm_runtime_status_suspended(thp7312->dev)) in thp7312_remove()
2231 pm_runtime_set_suspended(thp7312->dev); in thp7312_remove()
2252 MODULE_DESCRIPTION("THP7312 MIPI Camera Subdev Driver");