Lines Matching +full:i2c +full:- +full:crc +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-only
14 #include <linux/i2c.h>
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()
508 static int thp7312_stream_enable(struct thp7312_device *thp7312, bool enable) in thp7312_stream_enable() argument
510 return cci_write(thp7312->regmap, THP7312_REG_SET_OUTPUT_ENABLE, in thp7312_stream_enable()
511 enable ? THP7312_OUTPUT_ENABLE : THP7312_OUTPUT_DISABLE, 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()
534 return -EINVAL; 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()
595 dev_err(dev, "clk prepare enable failed\n"); 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()
800 static int thp7312_s_stream(struct v4l2_subdev *sd, int enable) in thp7312_s_stream() argument
808 if (!enable) { in thp7312_s_stream()
811 pm_runtime_put_autosuspend(thp7312->dev); in thp7312_s_stream()
818 ret = pm_runtime_resume_and_get(thp7312->dev); in thp7312_s_stream()
826 if (!thp7312->ctrls_applied) { in thp7312_s_stream()
827 ret = __v4l2_ctrl_handler_setup(&thp7312->ctrl_handler); in thp7312_s_stream()
831 thp7312->ctrls_applied = true; in thp7312_s_stream()
841 pm_runtime_put_autosuspend(thp7312->dev); in thp7312_s_stream()
862 fmt->code = MEDIA_BUS_FMT_YUYV8_1X16; in thp7312_init_state()
863 fmt->colorspace = V4L2_COLORSPACE_SRGB; in thp7312_init_state()
864 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in thp7312_init_state()
865 fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; in thp7312_init_state()
866 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); in thp7312_init_state()
867 fmt->width = default_mode->width; in thp7312_init_state()
868 fmt->height = default_mode->height; in thp7312_init_state()
869 fmt->field = V4L2_FIELD_NONE; in thp7312_init_state()
871 interval->numerator = 1; in thp7312_init_state()
872 interval->denominator = default_mode->rates[0].fps; in thp7312_init_state()
905 /* -----------------------------------------------------------------------------
911 return container_of(ctrl->handler, struct thp7312_device, ctrl_handler); in to_thp7312_from_ctrl()
924 enum thp7312_focus_state new_state = thp7312->focus_state; in thp7312_set_focus()
931 if (thp7312->focus_absolute->is_new) { in thp7312_set_focus()
934 value = thp7312_focus_values[thp7312->focus_absolute->val]; in thp7312_set_focus()
936 ret = cci_write(thp7312->regmap, in thp7312_set_focus()
943 switch (thp7312->focus_state) { in thp7312_set_focus()
946 if (thp7312->focus_auto->val) in thp7312_set_focus()
948 else if (thp7312->focus_start->is_new) in thp7312_set_focus()
953 if (!thp7312->focus_auto->val) in thp7312_set_focus()
958 if (thp7312->focus_auto->val) in thp7312_set_focus()
960 else if (thp7312->focus_start->is_new) in thp7312_set_focus()
962 else if (thp7312->focus_absolute->is_new) in thp7312_set_focus()
967 if (thp7312->focus_auto->val) in thp7312_set_focus()
969 else if (thp7312->focus_start->is_new) in thp7312_set_focus()
971 else if (thp7312->focus_absolute->is_new) in thp7312_set_focus()
978 * one-shot focus is requested, there's nothing new to program to the in thp7312_set_focus()
981 if (thp7312->focus_state == new_state && in thp7312_set_focus()
982 !thp7312->focus_method->is_new && !thp7312->focus_start->is_new) in thp7312_set_focus()
988 switch (thp7312->focus_method->val) { in thp7312_set_focus()
1021 cci_write(thp7312->regmap, THP7312_REG_AF_SETTING, af_setting, &ret); in thp7312_set_focus()
1024 (thp7312->focus_state == THP7312_FOCUS_STATE_AUTO || in thp7312_set_focus()
1025 thp7312->focus_state == THP7312_FOCUS_STATE_ONESHOT)) { in thp7312_set_focus()
1027 cci_write(thp7312->regmap, THP7312_REG_AF_CONTROL, in thp7312_set_focus()
1031 cci_write(thp7312->regmap, THP7312_REG_AF_CONTROL, af_control, &ret); in thp7312_set_focus()
1036 thp7312->focus_state = new_state; in thp7312_set_focus()
1047 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) in thp7312_s_ctrl()
1048 return -EINVAL; in thp7312_s_ctrl()
1050 if (!pm_runtime_get_if_active(thp7312->dev)) in thp7312_s_ctrl()
1053 switch (ctrl->id) { in thp7312_s_ctrl()
1055 cci_write(thp7312->regmap, THP7312_REG_BRIGHTNESS, in thp7312_s_ctrl()
1056 ctrl->val + 10, &ret); in thp7312_s_ctrl()
1061 cci_write(thp7312->regmap, THP7312_REG_AE_FIX_FRAME_RATE, in thp7312_s_ctrl()
1062 ctrl->val ? 0 : 1, &ret); in thp7312_s_ctrl()
1074 value = (thp7312->hflip->val ? THP7312_REG_FLIP_MIRROR_MIRROR : 0) in thp7312_s_ctrl()
1075 | (thp7312->vflip->val ? THP7312_REG_FLIP_MIRROR_FLIP : 0); in thp7312_s_ctrl()
1077 cci_write(thp7312->regmap, THP7312_REG_FLIP_MIRROR, value, &ret); in thp7312_s_ctrl()
1082 value = thp7312->noise_reduction_auto->val ? 0 in thp7312_s_ctrl()
1084 thp7312->noise_reduction_absolute->val; in thp7312_s_ctrl()
1086 cci_write(thp7312->regmap, THP7312_REG_NOISE_REDUCTION, value, in thp7312_s_ctrl()
1091 value = ctrl->val ? THP7312_WB_MODE_AUTO : THP7312_WB_MODE_MANUAL; in thp7312_s_ctrl()
1093 cci_write(thp7312->regmap, THP7312_REG_WB_MODE, value, &ret); in thp7312_s_ctrl()
1097 cci_write(thp7312->regmap, THP7312_REG_MANUAL_WB_RED_GAIN, in thp7312_s_ctrl()
1098 ctrl->val, &ret); in thp7312_s_ctrl()
1102 cci_write(thp7312->regmap, THP7312_REG_MANUAL_WB_BLUE_GAIN, in thp7312_s_ctrl()
1103 ctrl->val, &ret); in thp7312_s_ctrl()
1107 cci_write(thp7312->regmap, THP7312_REG_AE_EXPOSURE_COMPENSATION, in thp7312_s_ctrl()
1108 ctrl->val, &ret); in thp7312_s_ctrl()
1112 if (ctrl->val == V4L2_CID_POWER_LINE_FREQUENCY_60HZ) { in thp7312_s_ctrl()
1114 } else if (ctrl->val == V4L2_CID_POWER_LINE_FREQUENCY_50HZ) { in thp7312_s_ctrl()
1117 if (thp7312->fw_version == THP7312_FW_VERSION(40, 3)) { in thp7312_s_ctrl()
1125 cci_write(thp7312->regmap, THP7312_REG_AE_FLICKER_MODE, in thp7312_s_ctrl()
1130 cci_write(thp7312->regmap, THP7312_REG_SATURATION, in thp7312_s_ctrl()
1131 ctrl->val, &ret); in thp7312_s_ctrl()
1135 cci_write(thp7312->regmap, THP7312_REG_CONTRAST, in thp7312_s_ctrl()
1136 ctrl->val, &ret); in thp7312_s_ctrl()
1140 cci_write(thp7312->regmap, THP7312_REG_SHARPNESS, in thp7312_s_ctrl()
1141 ctrl->val, &ret); in thp7312_s_ctrl()
1148 pm_runtime_put_autosuspend(thp7312->dev); in thp7312_s_ctrl()
1158 * Refer to Documentation/userspace-api/media/drivers/thp7312.rst for details.
1163 .name = "Auto-Focus Method",
1174 .name = "Auto-Focus Method",
1214 -2000, -1667, -1333, -1000, -667, -333, 0, 333, 667, 1000, 1333, 1667, 2000
1219 struct v4l2_ctrl_handler *hdl = &thp7312->ctrl_handler; in thp7312_init_controls()
1220 struct device *dev = thp7312->dev; in thp7312_init_controls()
1229 * Check what auto-focus methods the connected sensor supports, if any. in thp7312_init_controls()
1233 if (thp7312->fw_version >= THP7312_FW_VERSION(90, 3)) { in thp7312_init_controls()
1236 ret = cci_read(thp7312->regmap, THP7312_REG_AF_SUPPORT, &val, in thp7312_init_controls()
1260 thp7312->focus_state = THP7312_FOCUS_STATE_MANUAL; in thp7312_init_controls()
1262 thp7312->focus_auto = in thp7312_init_controls()
1266 thp7312->focus_absolute = in thp7312_init_controls()
1271 thp7312->focus_method = in thp7312_init_controls()
1273 thp7312->focus_start = in thp7312_init_controls()
1278 v4l2_ctrl_cluster(4, &thp7312->focus_auto); in thp7312_init_controls()
1291 -10, 10, 1, 0); in thp7312_init_controls()
1299 thp7312->hflip = v4l2_ctrl_new_std(hdl, &thp7312_ctrl_ops, in thp7312_init_controls()
1301 thp7312->vflip = v4l2_ctrl_new_std(hdl, &thp7312_ctrl_ops, in thp7312_init_controls()
1304 v4l2_ctrl_cluster(2, &thp7312->hflip); in thp7312_init_controls()
1308 ARRAY_SIZE(exp_bias_qmenu) - 1, in thp7312_init_controls()
1316 thp7312->link_freq = thp7312_mode_info_data[0].rates[0].link_freq; in thp7312_init_controls()
1320 &thp7312->link_freq); in thp7312_init_controls()
1342 if (ctrl_cfg->id == V4L2_CID_THP7312_NOISE_REDUCTION_AUTO) in thp7312_init_controls()
1343 thp7312->noise_reduction_auto = ctrl; in thp7312_init_controls()
1344 else if (ctrl_cfg->id == V4L2_CID_THP7312_NOISE_REDUCTION_ABSOLUTE) in thp7312_init_controls()
1345 thp7312->noise_reduction_absolute = ctrl; in thp7312_init_controls()
1348 v4l2_ctrl_cluster(2, &thp7312->noise_reduction_auto); in thp7312_init_controls()
1350 if (hdl->error) { in thp7312_init_controls()
1352 ret = hdl->error; in thp7312_init_controls()
1356 link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in thp7312_init_controls()
1365 /* -----------------------------------------------------------------------------
1371 * variable-size "header". Both are stored in flash memory.
1379 * The SRAM is exposed over I2C as 32kB banks, and up to 4kB of data can be
1380 * transferred in a single I2C write.
1407 * BB BB BB: (write size - 1)
1413 * THP7312 Calculate CRC command
1417 * BB BB BB: (calculate size - 1)
1432 cci_read(thp7312->regmap, THP7312_REG_FIRMWARE_VERSION_1, &val, &ret); in thp7312_read_firmware_version()
1435 cci_read(thp7312->regmap, THP7312_REG_FIRMWARE_VERSION_2, &val, &ret); in thp7312_read_firmware_version()
1438 thp7312->fw_version = THP7312_FW_VERSION(major, minor); in thp7312_read_firmware_version()
1445 struct i2c_client *client = to_i2c_client(thp7312->dev); in thp7312_write_buf()
1455 struct device *dev = thp7312->dev; in __thp7312_flash_reg_write()
1462 return -EINVAL; in __thp7312_flash_reg_write()
1490 struct i2c_client *client = to_i2c_client(thp7312->dev); in __thp7312_flash_reg_read()
1498 msgs[0].addr = client->addr; in __thp7312_flash_reg_read()
1503 msgs[1].addr = client->addr; in __thp7312_flash_reg_read()
1508 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in __thp7312_flash_reg_read()
1521 struct device *dev = thp7312->dev; in thp7312_fw_prepare_config()
1524 ret = cci_write(thp7312->regmap, THP7312_REG_FW_MEMORY_IO_SETTING, in thp7312_fw_prepare_config()
1532 ret = cci_write(thp7312->regmap, THP7312_REG_FW_DRIVABILITY, 0x00777777, in thp7312_fw_prepare_config()
1544 struct device *dev = thp7312->dev; in thp7312_fw_prepare_check()
1563 struct device *dev = thp7312->dev; in thp7312_fw_prepare_reset()
1566 ret = cci_write(thp7312->regmap, THP7312_REG_FW_RESET_FLASH, 0x81, NULL); in thp7312_fw_prepare_reset()
1578 struct device *dev = thp7312->dev; in thp7312_flash_erase()
1589 dev_err(dev, "Failed to enable flash for writing\n"); in thp7312_flash_erase()
1627 struct device *dev = thp7312->dev; in thp7312_write_download_data_by_unit()
1628 u8 *write_buf = thp7312->fw_write_buf; in thp7312_write_download_data_by_unit()
1640 * Command ID (address to download): 0x0000 - 0x7fff in thp7312_write_download_data_by_unit()
1653 struct device *dev = thp7312->dev; in thp7312_fw_load_to_ram()
1668 ret = cci_write(thp7312->regmap, THP7312_REG_FW_DEST_BANK_ADDR, in thp7312_fw_load_to_ram()
1695 size -= chunk_size; in thp7312_fw_load_to_ram()
1715 command[cmd_size + 3] = ((write_size - 1) & 0xff0000) >> 16; in thp7312_fw_write_to_flash()
1716 command[cmd_size + 4] = ((write_size - 1) & 0x00ff00) >> 8; in thp7312_fw_write_to_flash()
1717 command[cmd_size + 5] = ((write_size - 1) & 0x0000ff); in thp7312_fw_write_to_flash()
1725 ret = cci_read(thp7312->regmap, THP7312_REG_FW_VERIFY_RESULT, &val, in thp7312_fw_write_to_flash()
1736 struct device *dev = thp7312->dev; in thp7312_fw_check_crc()
1737 u16 header_size = fw_size - THP7312_FW_RAM_SIZE; in thp7312_fw_check_crc()
1740 u32 size = THP7312_FW_RAM_SIZE - 4; in thp7312_fw_check_crc()
1742 u64 crc; in thp7312_fw_check_crc() local
1761 fw_crc = get_unaligned_be32(&fw_data[fw_size - 4]); in thp7312_fw_check_crc()
1763 ret = cci_read(thp7312->regmap, THP7312_REG_FW_CRC_RESULT, &crc, NULL); in thp7312_fw_check_crc()
1767 if (fw_crc != crc) { in thp7312_fw_check_crc()
1768 dev_err(dev, "CRC mismatch: firmware 0x%08x, flash 0x%08llx\n", in thp7312_fw_check_crc()
1769 fw_crc, crc); in thp7312_fw_check_crc()
1779 struct thp7312_device *thp7312 = fw_upload->dd_handle; in thp7312_fw_prepare()
1780 struct device *dev = thp7312->dev; in thp7312_fw_prepare()
1783 mutex_lock(&thp7312->fw_lock); in thp7312_fw_prepare()
1784 thp7312->fw_cancel = false; in thp7312_fw_prepare()
1785 mutex_unlock(&thp7312->fw_lock); in thp7312_fw_prepare()
1805 mutex_lock(&thp7312->fw_lock); in thp7312_fw_prepare()
1806 ret = thp7312->fw_cancel ? FW_UPLOAD_ERR_CANCELED : FW_UPLOAD_ERR_NONE; in thp7312_fw_prepare()
1807 mutex_unlock(&thp7312->fw_lock); in thp7312_fw_prepare()
1816 struct thp7312_device *thp7312 = fw_upload->dd_handle; in thp7312_fw_write()
1817 struct device *dev = thp7312->dev; in thp7312_fw_write()
1818 u16 header_size = size - THP7312_FW_RAM_SIZE; in thp7312_fw_write()
1822 mutex_lock(&thp7312->fw_lock); in thp7312_fw_write()
1823 cancel = thp7312->fw_cancel; in thp7312_fw_write()
1824 mutex_unlock(&thp7312->fw_lock); in thp7312_fw_write()
1845 ret = thp7312_fw_write_to_flash(thp7312, 0x20000, header_size - 1); in thp7312_fw_write()
1865 * This may be called asynchronously with an on-going update. All other
1872 struct thp7312_device *thp7312 = fw_upload->dd_handle; in thp7312_fw_cancel()
1874 mutex_lock(&thp7312->fw_lock); in thp7312_fw_cancel()
1875 thp7312->fw_cancel = true; in thp7312_fw_cancel()
1876 mutex_unlock(&thp7312->fw_lock); in thp7312_fw_cancel()
1888 struct device *dev = thp7312->dev; in thp7312_register_flash_mode()
1895 mutex_init(&thp7312->fw_lock); in thp7312_register_flash_mode()
1897 thp7312->fw_write_buf = devm_kzalloc(dev, THP7312_FW_DOWNLOAD_UNIT + 2, in thp7312_register_flash_mode()
1899 if (!thp7312->fw_write_buf) in thp7312_register_flash_mode()
1900 return -ENOMEM; in thp7312_register_flash_mode()
1906 ret = cci_read(thp7312->regmap, THP7312_REG_FW_STATUS, &val, NULL); in thp7312_register_flash_mode()
1912 fwl = firmware_upload_register(THIS_MODULE, dev, "thp7312-firmware", in thp7312_register_flash_mode()
1920 thp7312->fwl = fwl; in thp7312_register_flash_mode()
1928 /* -----------------------------------------------------------------------------
1936 for (i = 0; i < ARRAY_SIZE(thp7312->supplies); i++) in thp7312_get_regulators()
1937 thp7312->supplies[i].supply = thp7312_supply_name[i]; in thp7312_get_regulators()
1939 return devm_regulator_bulk_get(thp7312->dev, in thp7312_get_regulators()
1940 ARRAY_SIZE(thp7312->supplies), in thp7312_get_regulators()
1941 thp7312->supplies); in thp7312_get_regulators()
1947 struct device *dev = thp7312->dev; in thp7312_sensor_parse_dt()
1960 return -EINVAL; in thp7312_sensor_parse_dt()
1963 if (reg >= ARRAY_SIZE(thp7312->sensors)) { in thp7312_sensor_parse_dt()
1964 dev_err(dev, "Out-of-bounds 'reg' value %u\n", reg); in thp7312_sensor_parse_dt()
1965 return -EINVAL; in thp7312_sensor_parse_dt()
1968 sensor = &thp7312->sensors[reg]; in thp7312_sensor_parse_dt()
1969 if (sensor->info) { in thp7312_sensor_parse_dt()
1971 return -EINVAL; in thp7312_sensor_parse_dt()
1977 return -EINVAL; in thp7312_sensor_parse_dt()
1984 if (!strcmp(info->model, model)) { in thp7312_sensor_parse_dt()
1985 sensor->info = info; in thp7312_sensor_parse_dt()
1990 if (!sensor->info) { in thp7312_sensor_parse_dt()
1992 return -EINVAL; in thp7312_sensor_parse_dt()
1995 ret = fwnode_property_read_u32_array(node, "data-lanes", values, in thp7312_sensor_parse_dt()
1998 dev_err(dev, "Failed to read property data-lanes: %d\n", ret); in thp7312_sensor_parse_dt()
2005 ret = thp7312_map_data_lanes(&sensor->lane_remap, data_lanes, in thp7312_sensor_parse_dt()
2008 dev_err(dev, "Invalid sensor@%u data-lanes value\n", reg); in thp7312_sensor_parse_dt()
2020 struct device *dev = thp7312->dev; in thp7312_parse_dt()
2029 return dev_err_probe(dev, -EINVAL, "Endpoint node not found\n"); in thp7312_parse_dt()
2036 ret = thp7312_map_data_lanes(&thp7312->lane_remap, in thp7312_parse_dt()
2040 dev_err(dev, "Invalid data-lanes value\n"); in thp7312_parse_dt()
2045 * The thine,boot-mode property is optional and default to in thp7312_parse_dt()
2048 thp7312->boot_mode = THP7312_BOOT_MODE_SPI_MASTER; in thp7312_parse_dt()
2049 ret = device_property_read_u32(dev, "thine,boot-mode", in thp7312_parse_dt()
2050 &thp7312->boot_mode); in thp7312_parse_dt()
2051 if (ret && ret != -EINVAL) in thp7312_parse_dt()
2053 "thine,boot-mode"); in thp7312_parse_dt()
2055 if (thp7312->boot_mode != THP7312_BOOT_MODE_2WIRE_SLAVE && in thp7312_parse_dt()
2056 thp7312->boot_mode != THP7312_BOOT_MODE_SPI_MASTER) in thp7312_parse_dt()
2057 return dev_err_probe(dev, -EINVAL, "Invalid '%s' value %u\n", in thp7312_parse_dt()
2058 "thine,boot-mode", thp7312->boot_mode); in thp7312_parse_dt()
2064 return -EINVAL; in thp7312_parse_dt()
2078 return -EINVAL; in thp7312_parse_dt()
2086 struct device *dev = &client->dev; in thp7312_probe()
2092 return -ENOMEM; in thp7312_probe()
2094 thp7312->dev = dev; in thp7312_probe()
2096 thp7312->regmap = devm_cci_regmap_init_i2c(client, 16); in thp7312_probe()
2097 if (IS_ERR(thp7312->regmap)) in thp7312_probe()
2098 return dev_err_probe(dev, PTR_ERR(thp7312->regmap), in thp7312_probe()
2099 "Unable to initialize I2C\n"); in thp7312_probe()
2109 thp7312->iclk = devm_clk_get(dev, NULL); in thp7312_probe()
2110 if (IS_ERR(thp7312->iclk)) in thp7312_probe()
2111 return dev_err_probe(dev, PTR_ERR(thp7312->iclk), in thp7312_probe()
2114 thp7312->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); in thp7312_probe()
2115 if (IS_ERR(thp7312->reset_gpio)) in thp7312_probe()
2116 return dev_err_probe(dev, PTR_ERR(thp7312->reset_gpio), in thp7312_probe()
2119 if (thp7312->boot_mode == THP7312_BOOT_MODE_2WIRE_SLAVE) in thp7312_probe()
2122 v4l2_i2c_subdev_init(&thp7312->sd, client, &thp7312_subdev_ops); in thp7312_probe()
2123 thp7312->sd.internal_ops = &thp7312_internal_ops; in thp7312_probe()
2124 thp7312->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in thp7312_probe()
2125 thp7312->pad.flags = MEDIA_PAD_FL_SOURCE; in thp7312_probe()
2126 thp7312->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in thp7312_probe()
2128 ret = media_entity_pads_init(&thp7312->sd.entity, 1, &thp7312->pad); in thp7312_probe()
2133 * Enable power management. The driver supports runtime PM, but needs to in thp7312_probe()
2153 thp7312->sd.ctrl_handler = &thp7312->ctrl_handler; in thp7312_probe()
2154 thp7312->sd.state_lock = thp7312->ctrl_handler.lock; in thp7312_probe()
2156 ret = v4l2_subdev_init_finalize(&thp7312->sd); in thp7312_probe()
2163 * Enable runtime PM with autosuspend. As the device has been powered in thp7312_probe()
2173 ret = v4l2_async_register_subdev(&thp7312->sd); in thp7312_probe()
2186 THP7312_FW_VERSION_MAJOR(thp7312->fw_version), in thp7312_probe()
2187 THP7312_FW_VERSION_MINOR(thp7312->fw_version)); in thp7312_probe()
2194 v4l2_subdev_cleanup(&thp7312->sd); in thp7312_probe()
2196 v4l2_ctrl_handler_free(&thp7312->ctrl_handler); in thp7312_probe()
2200 media_entity_cleanup(&thp7312->sd.entity); in thp7312_probe()
2209 if (thp7312->boot_mode == THP7312_BOOT_MODE_2WIRE_SLAVE) { in thp7312_remove()
2210 firmware_upload_unregister(thp7312->fwl); in thp7312_remove()
2215 v4l2_async_unregister_subdev(&thp7312->sd); in thp7312_remove()
2216 v4l2_subdev_cleanup(&thp7312->sd); in thp7312_remove()
2217 media_entity_cleanup(&thp7312->sd.entity); in thp7312_remove()
2218 v4l2_ctrl_handler_free(&thp7312->ctrl_handler); in thp7312_remove()
2224 pm_runtime_disable(thp7312->dev); in thp7312_remove()
2225 if (!pm_runtime_status_suspended(thp7312->dev)) in thp7312_remove()
2227 pm_runtime_set_suspended(thp7312->dev); in thp7312_remove()