Lines Matching full:csi
4 * Intel Visual Sensing Controller CSI Linux driver
8 * To set ownership of CSI-2 link and to configure CSI-2 link, there
36 #define MEI_CSI_ENTITY_NAME "Intel IVSC CSI"
42 /* to setup CSI-2 link an extra delay needed and determined experimentally */
53 /* used to set csi ownership */
56 /* used to configure CSI-2 link */
63 /* CSI-2 link ownership definition */
82 /* configuration of the CSI-2 link between host and IVSC */
84 /* number of data lanes used on the CSI-2 link */
87 /* frequency of the CSI-2 link */
94 /* CSI command structure */
103 /* CSI notification structure */
137 /* number of data lanes used on the CSI-2 link */
139 /* frequency of the CSI-2 link */
170 static int mei_csi_send(struct mei_csi *csi, u8 *buf, size_t len) in mei_csi_send() argument
175 reinit_completion(&csi->cmd_completion); in mei_csi_send()
177 ret = mei_cldev_send(csi->cldev, buf, len); in mei_csi_send()
181 ret = wait_for_completion_killable_timeout(&csi->cmd_completion, in mei_csi_send()
191 ret = csi->cmd_response.status; in mei_csi_send()
195 v4l2_ctrl_s_ctrl(csi->privacy_ctrl, 1); in mei_csi_send()
201 if (csi->cmd_response.cmd_id != cmd->cmd_id) in mei_csi_send()
208 /* set CSI-2 link ownership */
209 static int csi_set_link_owner(struct mei_csi *csi, enum csi_link_owner owner) in csi_set_link_owner() argument
219 mutex_lock(&csi->lock); in csi_set_link_owner()
221 ret = mei_csi_send(csi, (u8 *)&cmd, cmd_size); in csi_set_link_owner()
223 mutex_unlock(&csi->lock); in csi_set_link_owner()
228 /* configure CSI-2 link between host and IVSC */
229 static int csi_set_link_cfg(struct mei_csi *csi) in csi_set_link_cfg() argument
236 cmd.param.conf.nr_of_lanes = csi->nr_of_lanes; in csi_set_link_cfg()
237 cmd.param.conf.link_freq = CSI_LINK_FREQ(csi->link_freq); in csi_set_link_cfg()
240 mutex_lock(&csi->lock); in csi_set_link_cfg()
242 ret = mei_csi_send(csi, (u8 *)&cmd, cmd_size); in csi_set_link_cfg()
251 mutex_unlock(&csi->lock); in csi_set_link_cfg()
259 struct mei_csi *csi = mei_cldev_get_drvdata(cldev); in mei_csi_rx() local
272 v4l2_ctrl_s_ctrl(csi->privacy_ctrl, in mei_csi_rx()
277 memcpy(&csi->cmd_response, ¬if, ret); in mei_csi_rx()
279 complete(&csi->cmd_completion); in mei_csi_rx()
288 struct mei_csi *csi = sd_to_csi(sd); in mei_csi_set_stream() local
292 if (enable && csi->streaming == 0) { in mei_csi_set_stream()
293 freq = v4l2_get_link_freq(csi->remote->ctrl_handler, 0, 0); in mei_csi_set_stream()
295 dev_err(&csi->cldev->dev, in mei_csi_set_stream()
300 csi->link_freq = freq; in mei_csi_set_stream()
302 /* switch CSI-2 link to host */ in mei_csi_set_stream()
303 ret = csi_set_link_owner(csi, CSI_LINK_HOST); in mei_csi_set_stream()
307 /* configure CSI-2 link */ in mei_csi_set_stream()
308 ret = csi_set_link_cfg(csi); in mei_csi_set_stream()
312 ret = v4l2_subdev_call(csi->remote, video, s_stream, 1); in mei_csi_set_stream()
315 } else if (!enable && csi->streaming == 1) { in mei_csi_set_stream()
316 v4l2_subdev_call(csi->remote, video, s_stream, 0); in mei_csi_set_stream()
318 /* switch CSI-2 link to IVSC */ in mei_csi_set_stream()
319 ret = csi_set_link_owner(csi, CSI_LINK_IVSC); in mei_csi_set_stream()
321 dev_warn(&csi->cldev->dev, in mei_csi_set_stream()
325 csi->streaming = enable; in mei_csi_set_stream()
330 csi_set_link_owner(csi, CSI_LINK_IVSC); in mei_csi_set_stream()
475 struct mei_csi *csi = ctrl_to_csi(ctrl); in mei_csi_g_volatile_ctrl() local
479 if (!csi->remote) in mei_csi_g_volatile_ctrl()
482 freq = v4l2_get_link_freq(csi->remote->ctrl_handler, 0, 0); in mei_csi_g_volatile_ctrl()
484 dev_err(&csi->cldev->dev, in mei_csi_g_volatile_ctrl()
528 struct mei_csi *csi = notifier_to_csi(notifier); in mei_csi_notify_bound() local
536 csi->remote = subdev; in mei_csi_notify_bound()
537 csi->remote_pad = pad; in mei_csi_notify_bound()
540 &csi->subdev.entity, CSI_PAD_SINK, in mei_csi_notify_bound()
549 struct mei_csi *csi = notifier_to_csi(notifier); in mei_csi_notify_unbind() local
551 csi->remote = NULL; in mei_csi_notify_unbind()
559 static int mei_csi_init_controls(struct mei_csi *csi) in mei_csi_init_controls() argument
564 mutex_init(&csi->ctrl_lock); in mei_csi_init_controls()
566 ret = v4l2_ctrl_handler_init(&csi->ctrl_handler, 2); in mei_csi_init_controls()
570 csi->ctrl_handler.lock = &csi->ctrl_lock; in mei_csi_init_controls()
573 csi->freq_ctrl = v4l2_ctrl_new_int_menu(&csi->ctrl_handler, in mei_csi_init_controls()
579 if (csi->freq_ctrl) in mei_csi_init_controls()
580 csi->freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY | in mei_csi_init_controls()
583 csi->privacy_ctrl = v4l2_ctrl_new_std(&csi->ctrl_handler, NULL, in mei_csi_init_controls()
585 if (csi->privacy_ctrl) in mei_csi_init_controls()
586 csi->privacy_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in mei_csi_init_controls()
588 if (csi->ctrl_handler.error) in mei_csi_init_controls()
589 return csi->ctrl_handler.error; in mei_csi_init_controls()
591 csi->subdev.ctrl_handler = &csi->ctrl_handler; in mei_csi_init_controls()
596 static int mei_csi_parse_firmware(struct mei_csi *csi) in mei_csi_parse_firmware() argument
601 struct device *dev = &csi->cldev->dev; in mei_csi_parse_firmware()
612 v4l2_async_subdev_nf_init(&csi->notifier, &csi->subdev); in mei_csi_parse_firmware()
613 csi->notifier.ops = &mei_csi_notify_ops; in mei_csi_parse_firmware()
621 csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes; in mei_csi_parse_firmware()
637 if (csi->nr_of_lanes != v4l2_ep.bus.mipi_csi2.num_data_lanes) { in mei_csi_parse_firmware()
641 csi->nr_of_lanes, v4l2_ep.bus.mipi_csi2.num_data_lanes); in mei_csi_parse_firmware()
645 asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, sink_ep, in mei_csi_parse_firmware()
652 ret = v4l2_async_nf_register(&csi->notifier); in mei_csi_parse_firmware()
661 v4l2_async_nf_cleanup(&csi->notifier); in mei_csi_parse_firmware()
672 struct mei_csi *csi; in mei_csi_probe() local
688 dev_err(dev, "mei-csi probed without device fwnode!\n"); in mei_csi_probe()
692 csi = devm_kzalloc(dev, sizeof(struct mei_csi), GFP_KERNEL); in mei_csi_probe()
693 if (!csi) in mei_csi_probe()
696 csi->cldev = cldev; in mei_csi_probe()
697 mutex_init(&csi->lock); in mei_csi_probe()
698 init_completion(&csi->cmd_completion); in mei_csi_probe()
700 mei_cldev_set_drvdata(cldev, csi); in mei_csi_probe()
714 ret = mei_csi_parse_firmware(csi); in mei_csi_probe()
718 csi->subdev.dev = &cldev->dev; in mei_csi_probe()
719 csi->subdev.state_lock = &csi->lock; in mei_csi_probe()
720 v4l2_subdev_init(&csi->subdev, &mei_csi_subdev_ops); in mei_csi_probe()
721 csi->subdev.internal_ops = &mei_csi_internal_ops; in mei_csi_probe()
722 v4l2_set_subdevdata(&csi->subdev, csi); in mei_csi_probe()
723 csi->subdev.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | in mei_csi_probe()
725 csi->subdev.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; in mei_csi_probe()
726 csi->subdev.entity.ops = &mei_csi_entity_ops; in mei_csi_probe()
728 snprintf(csi->subdev.name, sizeof(csi->subdev.name), in mei_csi_probe()
731 ret = mei_csi_init_controls(csi); in mei_csi_probe()
735 csi->pads[CSI_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; in mei_csi_probe()
736 csi->pads[CSI_PAD_SINK].flags = MEDIA_PAD_FL_SINK; in mei_csi_probe()
737 ret = media_entity_pads_init(&csi->subdev.entity, CSI_NUM_PADS, in mei_csi_probe()
738 csi->pads); in mei_csi_probe()
742 ret = v4l2_subdev_init_finalize(&csi->subdev); in mei_csi_probe()
746 ret = v4l2_async_register_subdev(&csi->subdev); in mei_csi_probe()
755 v4l2_subdev_cleanup(&csi->subdev); in mei_csi_probe()
758 media_entity_cleanup(&csi->subdev.entity); in mei_csi_probe()
761 v4l2_ctrl_handler_free(&csi->ctrl_handler); in mei_csi_probe()
762 mutex_destroy(&csi->ctrl_lock); in mei_csi_probe()
763 v4l2_async_nf_unregister(&csi->notifier); in mei_csi_probe()
764 v4l2_async_nf_cleanup(&csi->notifier); in mei_csi_probe()
770 mutex_destroy(&csi->lock); in mei_csi_probe()
777 struct mei_csi *csi = mei_cldev_get_drvdata(cldev); in mei_csi_remove() local
779 v4l2_async_nf_unregister(&csi->notifier); in mei_csi_remove()
780 v4l2_async_nf_cleanup(&csi->notifier); in mei_csi_remove()
781 v4l2_ctrl_handler_free(&csi->ctrl_handler); in mei_csi_remove()
782 mutex_destroy(&csi->ctrl_lock); in mei_csi_remove()
783 v4l2_async_unregister_subdev(&csi->subdev); in mei_csi_remove()
784 v4l2_subdev_cleanup(&csi->subdev); in mei_csi_remove()
785 media_entity_cleanup(&csi->subdev.entity); in mei_csi_remove()
789 mutex_destroy(&csi->lock); in mei_csi_remove()
814 MODULE_DESCRIPTION("Device driver for IVSC CSI");